Content deleted Content added
Fixed typo Tags: canned edit summary Mobile edit Mobile app edit iOS app edit |
→Whitespace and semicolons: big overall change made of quite a few small stuff Tags: nowiki added Visual edit |
||
Line 25:
===Whitespace and semicolons===
|title=JavaScript: The definitive Guide
|url=https://archive.org/details/javascript00libg_297
Line 38:
There are two issues: five tokens can either begin a statement or be the extension of a complete statement; and five restricted productions, where line breaks are not allowed in certain positions, potentially yielding incorrect parsing.<ref name="inimino" />
The five problematic tokens are the open parenthesis "<tt>(</tt>", open bracket "<tt>[</tt>", slash "<tt>/</tt>", plus "<tt>+</tt>", and minus "<tt>-</tt>". Of these, the open parenthesis is common in the [[immediately-invoked function expression]] pattern, and open bracket occurs sometimes, while others are quite rare. The example given in the spec<!-- The blog is not a spec[ification] --> is:<ref name="inimino" />
<syntaxhighlight lang="javascript">
Line 88:
==Variables==
[[Variable (programming)|Variable]]s in standard JavaScript have no [[Type system|type]] attached,<!-- Wait, variables do have a type, but you don't declare it. Also there's type coercion. --> and any value can be stored in any variable. Before ES6, variables were declared only with a <code>var</code> statement. Starting with [[ECMAScript#6th Edition - ECMAScript 2015|ES6]], the version of the language finalised in 2015, variables can also be declared with <code>let</code>
Starting with JavaScript 1.5, [[ISO 8859-1]] or [[Unicode]] letters (or <tt>\uXXXX</tt> Unicode escape sequences) can be used in identifiers.<ref>{{cite web | url=https://developer.mozilla.org/en/JavaScript/Guide/Values,_Variables,_and_Literals&revision=22#Variables | title=Values, Variables, and Literals - MDC | date=16 September 2010 | publisher=Mozilla Developer Network | access-date=1 February 2020 | archive-url=https://web.archive.org/web/20110629131728/https://developer.mozilla.org/en/JavaScript/Guide/Values%2C_Variables%2C_and_Literals%26revision%3D22#Variables | archive-date=29 June 2011 | url-status=dead }}</ref> In certain JavaScript implementations, the at sign (@) can be used in an identifier, but this is contrary to the specifications and not supported in newer implementations.
Line 94:
===Scoping and hoisting===
Variables declared with <code>var</code> are [[lexical scoping|lexically scoped]] at a [[function scope|function level]],
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.
|