Grammatical composition, keywords and reserved words, variables

Source: Internet
Author: User

1. Syntax

1.1 If the introduction of external JS, then in the script tag can not write the JS code

<script src= "" ></script>

1.2 Case-sensitive

1.3 Identifier composition begins with: A (letter), _, $

1.4 Cannot put keyword, reserved word, true false null as identifier

2. Variables

var a;//create (DECLARE) variable var a=1;//create variable, and variable initialization; a=1+a;//variable operation

3. Data type

var a;//create variable var a=1;//create variable, and variable initialization; Action of a=1+a;//variable a = 1;//value Numbera = 0.01;//integer and real number share a data type Numbera = ' Hello world ';//String St Ringa = "JavaScript";//double-quoted string Stringa = true;//Boolean Booleana = false;//to True the opposite Boolean value Booleana =null; The null type is a privileged value, meaning ' empty ' Nulla =undefined;//undefined and null are very similar undefined
A = {}; Objects Object

The difference between 3.1undefined and null

Undefined

A. There is no need to assign a value of undefined to a variable, or it can be ' empty ', and JS will automatically assign undefined to undefined variables.

B. Declaring variables must be initialized.

var a;//create variable alert (a); Undefined undefined variables will pop up

Null

A. Objects that represent "empty"

var B = {};alert (typeof B); B is a null type, the returned value [Object Object], the string of the return type is Objectalert (b);//Popup [Object Object]

Example:

alert (undefined = = null); Returns Truealert (undefined = = = null);//returns Falsealert (typeof undefined = = typeof null); Returns false

4.TYPEPOF (String that returns the type of data)

Example 1:

var a=1;//create variable alert (typeof a); Will pop up number A is the # type, the value is 1, and the string that returns the type is #

Example 2:

var B;alert (typeof B)//b is the undefined type, the return value is undefined, and the string of the return type is undefined

Example 3

var B = Null;alert (typeof b)//b is a null type, the returned value [Object Object], the string of the return type is an object

5. Initialization of different data types

var box = '; String initialization is generally an empty string var box = 0;//number initialization, generally with 0var box = False;//boolean initialization, generally false or True;var box = {}; Obeject, generally with empty objects

Implicit conversion of 6.Boolean

Grammatical composition, keywords and reserved words, variables

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.