JavaScript basic Syntax &1

Source: Internet
Author: User

1. Identifiers and reserved words
Identifiers: Typically variable names, which can consist of numbers & letters &$& underscores; The first character cannot be a number;
Reserved words: Typically a word that has a special meaning inside JavaScript, or a new property or method that is about to be added, not when the identifier name is used;
2. Notes
JavaScript annotations fall into two categories:
The contents of a single line comment//comment
The contents of a multiline comment/* Comment */
The Code compression tool does not delete this comment when a multiline comment is written as the content of the/*! comment * *;


3. Strict mode
Add ' use static ' at the beginning of the function or document; can open strict mode, it is recommended to open strict mode, develop good coding habits;
If the browser does not support strict mode, the line is automatically ignored;
  * in strict mode, you cannot assign values to undeclared variables and do not support with syntax;


4. Variables
Variables are divided into global variables and local variables, which can generally be accessed by using window. Variable names are the global variables that all functions can access;
Declared inside the function body, only variables that can be accessed inside the function are local variables;
Variables are declared with the keyword Var, for example varage; You can assign values to variables at the same time as variable declarations, for example:var age =Max;
Constants, there is no concept of constants in JavaScript, the general Convention is to capitalize all the identifiers of constants for example: var age =;


5.type
Variables are divided into: numbers, strings, booleans, arrays, functions, objects, date objects, RegEXP;
How to identify the type of the variable, generally using the operator typeof variable name, but the typeof operator returns the result is not accurate; You can use the following function to identify the type of the variable;

function type (obj) {  // return value is lowercase number, string, Boolean, array, function, object, date, regexp, Undefined, nu ll; return  Object.prototype.toString.call (obj). Slice (8,-1). toLowerCase (); }  

6.null && undefined
Null indicates that there is no;
Undefined indicates existence but no value;
Returns True when the = = comparison is used;

JavaScript basic Syntax &1

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.