Content deleted Content added
→Operators: adding an excerpt describing the "??" operator |
IznoRepeat (talk | contribs) m invert mvar-link placement for upcoming tstyles |
||
Line 119:
When JavaScript tries to '''resolve''' an identifier, it looks in the local scope. If this identifier is not found, it looks in the next outer scope, and so on along the ''scope chain'' until it reaches the ''global scope'' where global variables reside. If it is still not found, JavaScript will raise a <code>ReferenceError</code> exception.
When '''assigning''' an identifier, JavaScript goes through exactly the same process to retrieve this identifier, except that if it is not found in the ''global scope'', it will create the "variable" in the scope where it was created.
Note that JavaScript's ''strict mode'' forbids the assignment of an undeclared variable, which avoids global namespace pollution. <!-- Removed, unrelated to the first statement and sentence was already stated. Delete this comment if you edit this, this is just an explanation for my big edit. -->
Line 203:
Here, calling <code>isUndefined(my_var)</code> raises a {{mono|ReferenceError}} if {{mono|my_var}} is an unknown identifier, whereas {{code|lang=javascript|code=typeof my_var === 'undefined'}} doesn't.
===Number===
Line 550 ⟶ 548:
!Property!!Returned value<br />rounded to 5 digits!!Description
|-
| <tt>Math.E</tt> || align=center|2.7183 || {{mvar|[[e (mathematical constant)
|-
| <tt>Math.LN2</tt> || align=center|0.69315 || [[Natural logarithm]] of 2
Line 1,221 ⟶ 1,219:
str2 = "2" + 2; // "22", not "4" or 4.
</syntaxhighlight>
===??===
{{excerpt|Null coalescing operator|JavaScript}}
|