Google

Lexical Structure

Case Sensitivity


JavaScript is a case-sensitive language. This means that you must pay attention to your uppercase and lowercase letters.
all language keywords, variables, function names, and other identifiers must always be typed with a consistent capitalization of letters.
as examples,
 javascript is not the same as javaScript .
the "for" keyword must be typed "for" not "For" or "FOR" .
Also, you must refer to built-in objects with the proper casing. Date start with uppercase letters, but not window. Most built-in methods are combined words by capitalizing all but the first,
such as getElementById (often referred to as camelCase).

Note, however, that HTML is not case-sensitive (although XHTML is). Because of its
close association with client-side JavaScript, this difference can be confusing. Many
client-side JavaScript objects and properties have the same names as the HTML tags
and attributes they represent. While these tags and attribute names can be typed in any
case in HTML, in JavaScript they typically must be all lowercase. For example, the
HTML onclick event handler attribute is sometimes specified as onClick in HTML, but
it must be specified as onclick in JavaScript code (or in XHTML documents).


Comments


Comments are an important  even though they don’t actually do anything. They are helpful hints for people who read the program.

JavaScript supports two styles of comments.
Any text between a // and the end of a line is treated as a comment and is ignored by JavaScript. Any text between the characters /* and */ is also treated as a comment; these comments may span multiple lines but may not be nested.

Single-line comments :


// This is a single-line comment
return true; // Comment after code

Multiline comments :


/* This comment can wrap
into the next line
 this comment has multiple lines.
 */

Whitespace and New Lines


Most whitespace such as spaces, tabs, and empty lines is ignored in JavaScript and you can them to format and indent your program to make  the code easy to read and understand.


Semicolons


JavaScript statements should end with semicolon (;).
Technically they are optional, but that’s only because JavaScript interpreters add them automatically at the end of most lines.It’s best to get into the habit of adding the semicolons yourself because there can be strange side effects when you let the interpreter do it for you.

In JavaScript, you can usually omit the semicolon between two statements if those statements are written on separate lines. (You can also omit a semicolon at the end of a program or if the next token in the program is a closing curly brace }.) Many JavaScript programmers  use semicolons to explicitly mark the ends of statements, even where they are not required.



Reserved Words

JavaScript reserves certain words for specific uses, so be careful to avoid the following unless you mean to use them:


break    -    case    -   catch    -  continue    -  default

delete     -  do    -   else   -    finally  -     for   -   function

if  -  in  -  instanceof  - new - return - switch - this - throw

try   -   typeof   -   var   -   void   -    while   -    with


You should also avoid these words because they may be used in futureversions of JavaScript:


abstract    -   boolean   -  byte   -    char   -   class    -   const

debugger   -    double   -    enum   -   export   -   extends

final    -    float    -   goto    -   implements    -   import

int    -    interface    -   long    -   native   -   package   -   private

protected   -   public   -   short   -   static   -   super   -  synchronized

throws   -   transient   -   volatile


These words refer to useful objects in the language and Web pages, so be careful not to redefine them with your own values:


arguments  -   Array   -   Boolean   -   Date   -   decodeURI

decodeURIComponent   -   encodeURI   -   Error   -   escape

eval   -   EvalError   -   Function   -   Infinity   -    isFinite

isNaN   -   Math   -   NaN   -   Number   -   Object

parseFloat   -   parseInt   -   RangeError   -   ReferenceError

RegExp   -   String   -   SyntaxError   -   TypeError

undefined   -   unescape   -   URIError

No comments: