| FazBrowse Wikipedia Viewer | Main Page | | |
| Viewing: https://en.wikipedia.org/wiki/JavaScript_syntax |
| Contents |
|---|
| Literal values |
| Removed keywords |
| Case sensitivity |
The syntax of JavaScript is the set of rules that define a correctly structured JavaScript program.
The examples below make use of the console.log() function present in most browsers for standard text output.
The JavaScript standard library lacks an official standard text output function (with the exception of document.write). Given that JavaScript is mainly used for client-side scripting within modern web browsers, and that almost all web browsers provide the alert function, alert can also be used, but it is not commonly used.
TypeScript, which extends JavaScript with type annotations and additional features, has the same syntax as well as its own additional features.
The following words refer to literal values used by the language:
true</code>\n* <code>false</code>\n* <code>null</code>\n",{"template":{"target":{"wt":"div col end","href":"./Template:Div_col_end"},"params":{},"i":1}}]}'>The following words, primarily associated with Java, were removed from the ECMAScript 5/6 standard:
abstract</code>\n* <code>boolean</code>\n* <code>byte</code>\n* <code>char</code>\n* <code>double</code>\n* <code>final</code>\n* <code>float</code>\n* <code>goto</code>\n* <code>int</code>\n* <code>long</code>\n* <code>native</code>\n* <code>short</code>\n* <code>synchronized</code>\n* <code>throws</code>\n* <code>transient</code>\n* <code>volatile</code>\n",{"template":{"target":{"wt":"div col end","href":"./Template:Div_col_end"},"params":{},"i":1}}]}'>JavaScript is case sensitive. It is common to start the name of a constructor with a capitalized letter, and the name of a function or variable with a lower-case letter.
Example:
Initial semicolons are also sometimes used at the start of JavaScript libraries, in case they are appended to another library that omits a trailing semicolon, as this can result in ambiguity of the initial statement. In such a case where perhaps unusual semicolon placement occurs, it may just be better to manually place semicolons at the end of statements.
The five restricted productions are return, throw, break, continue, and post-increment/decrement. In all cases, inserting semicolons does not fix the problem, but makes the parsed syntax clear, making the error easier to detect. return and throw take an optional value, while break and continue take an optional label. In all cases, the advice is to keep the value or label on the same line as the statement. This most often shows up in the return statement, where one might return a large object literal, which might be accidentally placed starting on a new line. For post-increment/decrement, there is potential ambiguity with pre-increment/decrement, and again it is recommended to simply keep these on the same line.
a" through "varx=1 statement in the middle of the function is equivalent to a| View original on Wikipedia | Back | FazBrowse Home |