JS Basics 1. Simple JS syntax keyword reserved word variable

Source: Internet
Author: User

Simple JS

JavaScript is a loose language object property but does not want C in the struct or C + + and Java objects, object inheritance mechanism using prototype prototype (prototype chain), JS is divided into three parts ECMAScript, document DOM object, browser BOM object

1. Core (ECMAScript) (syntax, type, statement, keyword, reserved word, operator, object, etc.) Ie6, 7, 8 third edition (ECMA-262) compatible

2. Document Object Dom (ie6-7 basic DOM level (basic operation can),)

3. Browser object model BOM (control browser display no standards, each browser is not the same level of support)

Supplemental browser kernel Learn about and pick the test environment IE browser Kernel Trident, Mozilla Gecko, Google WebKit, opera kernel presto (now using WebKit), Safari WebKit

For JavaScript needs a smooth degradation hint HTML noscript tags that do not support JavaScript

  <noscript><!--Smooth degradation does not support JavaScript processing: Do not use JavaScript for hints - you do not have JavaScript enabled </noscript>

Grammar

is case sensitive.

Identifier

The so-called identifier refers to the name of a variable, function, property, or parameter of a function. Identifiers can be one or more characters that are combined by the following formatting rules:

1. The first character must be a letter, an underscore (_), or a dollar sign ($).

2. Other characters can be letters, underscores, dollar signs, or numbers.

3. You cannot use keywords, reserved words, true, false, and NULL as identifiers.

For example: MyName, book123, etc.

Comments

ECMAScript uses C-style annotations, including single-line comments and block-level annotations.

Single-line Comment

/*

* This is a multi-line

* Notes

*/

Keywords (characters used by the program, keywords are reserved, cannot be used as variable names or function names)

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

Reserved words (JavaScript is not yet available, most likely later)

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

Variable

The ECMAScript variable is loosely typed, and the so-called loose type is used to hold any type of data. Use the var operator when defining variables (Var is key), followed by a variable name (the variable name is an identifier)

var box;//create variable not initialized

alert (box);//The system will give it a special value--undefined (means undefined)

Initialization is generally required when declaring variables

Variable is the amount that can be changed again after initialization. ECMAScript is a weakly typed (loosely typed) language that can change the amount of different types at the same time. (PS: Although different types of quantities can be changed, this is difficult for later maintenance and performance is not high)

Repeat using VAR to declare a variable, but it is an assignment operation, and does not give an error. There is no need.

You can omit semicolons when each statement is in a different row . (Although ECMAScript supported, but a very bad programming habit ).

var box= '

var age= 100

You can use a statement to define multiple variables, as long as each variable (initialization or uninitialized can be) separated by commas, for readability, each variable, preferably another row, and the second variable and the first variable alignment (beautiful ).

var box= ',

Age = 1,

Height=1;

When the variable declaration does not use VAR declaration that the variable will become a global variable under the same Window object, there will be a variety of post-maintenance, and team development problems as far as possible to avoid

JS Basics 1. Simple JS syntax keyword reserved word variable

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.