JavaScript syntax: Difference between revisions

Content deleted Content added
Undid revision 897751021 by BZAW31559 (talk) -- pointless empty section
m Primitive data types: {{code|lang=javascript|code=}}
Line 183:
</syntaxhighlight>
 
Note: There is no built-in language literal for undefined. Thus <{{code>|lang=javascript|code=(x == undefined)</code>}} is not a foolproof way to check whether a variable is undefined, because in versions before ECMAScript 5, it is legal for someone to write <{{code>|lang=javascript|code=var undefined = "I'm defined now";</code>}}. A more robust approach is to compare using <{{code>|lang=javascript|code=(typeof x === 'undefined')</code>}}.
 
Functions like this won't work as expected:
Line 198:
Unlike undefined, [[Null Object pattern|null]] is often set to indicate that something has been declared, but has been defined to be empty. In a Boolean context, the value of null is considered a false value in JavaScript.
 
Note: Null is a true primitive-type within the JavaScript language, of which {{mono|null}} (note case) is the single value. As such, when performing checks that enforce type checking, the null value will not equal other false types. Surprisingly, {{mono|null}} is considered an object by {{mono|[[typeof]]}}.
 
<syntaxhighlight lang="javascript">