Content deleted Content added
→If … else: Unnecessary reexplanation provided, thus removed |
No edit summary Tag: nowiki added |
||
Line 84:
Variables are [[lexical scoping|lexically scoped]] at [[function scope|function level]] (not [[block scope|block level]] as in C), and this does not depend on order ([[forward declaration]] is not necessary): if a variable is declared inside a function (at any point, in any block), then inside the function, the name will resolve to that variable. This is equivalent in block scoping to variables being forward declared at the top of the function, and is referred to as ''{{visible anchor|hoisting}}''.<ref>"[http://www.adequatelygood.com/JavaScript-Scoping-and-Hoisting.html JavaScript Scoping and Hoisting]", [http://www.adequatelygood.com/about.html Ben Cherry], ''[http://www.adequatelygood.com/ Adequately Good],'' 2010-02-08</ref>
However, the variable value is <code>undefined</code> until it is initialized, and [[forward reference]] is not possible. Thus a
Function statements, whose effect is to declare a variable of type <code>Function</code> and assign a value to it, are similar to variable statements, but in addition to hoisting the declaration, they also hoist the assignment – as if the entire statement appeared at the top of the containing function – and thus forward reference is also possible: the ___location of a function statement within an enclosing function is irrelevant.
Line 450:
===Math===
The <tt>Math</tt> object contains various math-related constants (for example,
{| class="wikitable" border="1"
|+ Properties of the Math object
|-
!Property!!Returned value<br />rounded to 5 digits!!Description
|-
| <tt>Math.E</tt> || align=center|2.7183 || ''[[e (mathematical constant)|e]]'': Natural logarithm base
Line 467:
| <tt>Math.LOG10E</tt> || align=center|0.43429 || Logarithm to the base 10 of ''e''
|-
| <tt>Math.PI</tt> || align=center|3.14159 || [[Pi|
|-
| <tt>Math.SQRT1_2</tt> || align=center|0.70711 || [[Square root]] of ½
Line 477:
|+ Methods of the Math object
|-
!Example!!Returned value<br />rounded to 5 digits!!Description
|-
| <tt>Math.abs(-2.3)</tt> || align=center|2.3 || Absolute value: <tt>(x < 0) ? -x : x</tt>
Line 485:
| <tt>Math.asin(Math.SQRT1_2)</tt> || align=center|0.78540 rad. = 45° || [[Arcsine]]
|-
| <tt>Math.atan(1)</tt> || align=center|0.78540 rad. = 45° || Half circle [[arctangent]] (-
|-
| <tt>Math.atan2(-3.7, -3.7)</tt> || align=center|-2.3562 rad. = -135° || Whole circle arctangent (-
|-
| <tt>Math.ceil(1.1)</tt> || align=center|2 || Ceiling: [[rounding|round]] up to smallest integer ≥ argument
Line 938:
| align="center" | <tt><<</tt> || shift left (zero fill)
|-
| align="center" | <tt>>></tt> || shift right (sign-propagating); copies of the<br />leftmost bit (sign bit) are shifted in from the left
|-
| align="center" | <tt>>>></tt> || shift right (zero fill). For positive numbers,<br /><tt>>></tt> and <tt>>>></tt> yield the same result.
|}
Line 1,061:
* Iterates through all enumerable properties of an object.
* Iterates through all used indices of array including all user-defined properties of array object, if any. Thus it may be better to use a traditional for loop with a numeric index when iterating over arrays.
* There are differences between the various Web browsers with regard to which properties will be reflected with the for...in loop statement. In theory, this is controlled by an internal state property defined by the ECMAscript standard called "DontEnum", but in practice, each browser returns a slightly different set of properties during introspection. It is useful to test for a given property using
===While loop===
Line 1,150:
Functions are [[first class object]]s and may be assigned to other variables.
The number of arguments given when calling a function may not necessarily correspond to the number of arguments in the function definition; a named argument in the definition that does not have a matching argument in the call will have the value {{mono|undefined}} (that can be implicitly cast to false). Within the function, the arguments may also be accessed through the {{mono|arguments}} object; this provides access to all arguments using indices (e.g.
<syntaxhighlight lang=JavaScript>
|