JavaScript syntax: Difference between revisions

Content deleted Content added
Line 205:
 
===Null===
Unlike undefined, [[Null Object pattern|null]] is often setused to indicateacknowledge thatthe somethingabsence hasof beena declaredvalue, butsuch hasas beendeclaring defineda variable as <tt>null</tt> to berepresent that the variable is defined, but does not have a emptyvalue. 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. Carried over from early days of JavaScript, <tt>null</tt> is considered an object by <tt>[[typeof]]</tt><ref>https://2ality.com/2013/10/typeof-null.html</ref>
 
<syntaxhighlight lang="javascript">
console.log(null == undefined); // unenforced type during check, displays=> true
console.log(null === undefined); // enforceenforced type during check, displays=> false
console.log(typeof null === 'object'); // => true
</syntaxhighlight>
 
It's helpful to recognize <tt>null</tt> as a different value then <tt>undefined</tt>. For example, a function could return <tt>null</tt> to represent that a given argument is not within the parameters of the function, or that an action could not be completed.
Initially the {{mono|[[typeof]]}} {{mono|null}} result caused by sequence of a coincidences. Though nowadays there might be an explanation, as null is shown at the end of Prototype Chain when there is no inheritance anymore. It is helpful to know null has a special usage, that is the difference from other primitives.
 
===Number===