DEV Community

Discussion on: Pragmatic types: is JavaScript an untyped language?

Collapse
 
codevault profile image
Sergiu Mureşan • Edited

Really great coverage of types!

There are also some issues when checking for booleans since:

if (someObj.isValid) { ... }

Works fine, but depends what you really mean by this condition. If you are checking the actual value of someObj.isValid this will enter the if block only if it is true but if you are checking if someObj has the property isValid then this will return false when its value is either undefined or false so we would have to change our if condition:

if (someObj.isValid !== undefined) { ... }

This might be bad practice (correct me if that's the case), but for a beginner it is hard to understand why you need that. Especially if isValid is an array or string.

Collapse
 
stereobooster profile image
stereobooster

Good reminder. Type systems can protect against it. In terms of Flow it is called "sketchy" values. I need to write a small post about it.