Content deleted Content added
BOT--Reverting link addition(s) by Coderlipi to revision 948179315 (www.youtube.com/watch?v=zBPeGR48_vE&list=PLqkLaKB2GJhWXV9rcarwvn06ISlL_9mPQ&index=1 [\byoutube\.com]) |
|||
Line 1:
{{
The '''[[Syntax (programming languages)|syntax]] of [[JavaScript]]''' is the set of rules that define a correctly structured JavaScript program.
Line 48 ⟶ 49:
with the suggestion that the preceding statement be terminated with a semicolon.
Some suggest instead the use of ''leading'' semicolons on lines starting with '<tt>(</tt>' or '<tt><nowiki>[</nowiki></tt>', so the line is not accidentally joined with the previous one. This is known as a '''defensive semicolon''', and is particularly recommended, because code may otherwise become ambiguous when it is rearranged.<ref name="inimino">"[http://inimino.org/~inimino/blog/javascript_semicolons JavaScript Semicolon Insertion: Everything you need to know]", [http://inimino.org/~inimino/blog/ ~inimino/blog/], Friday, 28 May
<syntaxhighlight lang="javascript">
Line 87 ⟶ 88:
==Variables==
[[Variable (programming)|Variable]]s in standard JavaScript have no [[Type system|type]] attached, and any value can be stored in any variable. Starting with [[ECMAScript#
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 105 ⟶ 106:
</syntaxhighlight>
Block scoping can be produced by wrapping the entire block in a function and then executing it
===Declaration and assignment===
Line 1,125 ⟶ 1,126:
|NOT
|-
| align="center" | <tt><<</tt> || shift left
|-
| align="center" | <tt>>></tt> || shift right (sign-propagating); copies of the<br />leftmost bit (sign bit) are shifted in from the left
Line 1,158 ⟶ 1,159:
| align="center" | <tt>^=</tt> || xor
|-
| align="center" | <tt><<=</tt> || shift left
|-
| align="center" | <tt>>>=</tt> || shift right (sign-propagating); copies of the<br />leftmost bit (sign bit) are shifted in from the left
Line 1,659 ⟶ 1,660:
===eval (expression) ===
Evaluates expression string parameter, which can include assignment statements. Variables local to functions can be referenced by the expression. However, the {{code|eval}} represents a major security risk, as it allows a bad actor to execute arbitrary code, and so its use is discouraged.<ref name="deve_eval">{{Cite web |title=eval()
<syntaxhighlight lang="javascript">
(function foo() {
Line 1,678 ⟶ 1,679:
* David Flanagan, Paula Ferguson: ''JavaScript: The Definitive Guide'', O'Reilly & Associates, {{ISBN|0-596-10199-6}}.
* Thomas A. Powell, Fritz Schneider: ''JavaScript: The Complete Reference'', McGraw-Hill Companies, {{ISBN|0-07-219127-9}}.
* Axel Rauschmayer: ''Speaking JavaScript: An In-Depth Guide for Programmers'', 460 pages, O'Reilly Media,
* Emily Vander Veer: ''JavaScript For Dummies, 4th Edition'', Wiley, {{ISBN|0-7645-7659-3}}.
Line 1,693 ⟶ 1,694:
{{JavaScript}}
▲{{Use dmy dates|date=April 2011}}
{{DEFAULTSORT:Javascript Syntax}}
|