Basic JavaScript Concepts

Source: Internet
Author: User

First, Strict mode

1. ECMAScript5 introduced the concept of strict pattern (strict mode). The intent is to define a different parsing and execution pattern for JavaScript.

2, the difference in strict mode:

(1), some uncertain behavior will be processed.

(2), some unsafe operations will also throw an exception.

To enable strict mode in a script, add code at the top:

 
   
  
  1. use strict

3, in strict mode, JavaScript execution results will be very different.

4. The following browsers support strict mode:

ie10+

Firefox 4+

Safari 5.1+

Opera 12+

Chrome

Second, the variable

1, ECMAScript variables are loosely typed, that is, can be used to hold any type of data, each variable is just a placeholder for the value to save.

2, uninitialized variables, will automatically save undefined.

3. Scope of variables:

(1), a variable defined with the var operator becomes a local variable in the scope that defines the variable. If you use var to define a variable in a function, the variable is destroyed after the function exits.

(2), the variable message is defined in the function using Var, and when the function is called, the variable is created and assigned a value. And then this variable will be destroyed immediately.

 
   
  
  1. function test(){
  2.     var message="h1";//局部变量
  3. }
  4. test();
  5. console.log(message);//报错

(3), when the Var operation is ignored (implicit variable nomenclature), the message becomes a global variable. So as long as the test () is called, the variable is defined and can be accessed anywhere outside the function.

(4), although ignoring the var operator can make a variable a global variable, this method is not recommended. Because it is difficult to maintain a global variable defined in a local scope, the VAR operator is deliberately ignored, and unnecessary confusion is caused by the corresponding variable not being defined immediately. In strict mode, assigning a value to an undeclared variable throws a referenceerror error. * in STARCT Mode in ECMAScript version 5th, the implicit global variable has been determined to be an error.

 
   
  
  1. function test(){
  2.     message="h1";
  3. }
  4. test();
  5. console.log(message);
  6.  //输出“hi”

Third, the data type

1. There are 5 simple data types in ECMAScript (basic data type)

 
   
  
  1. Undefined
  2. Null
  3. Boolean
  4. Number
  5. String

2, 1 types of complex data

Object

Essentially consists of a set of unordered name-value pairs

3. Typefo operator

(1), a type of operator used to detect variable data types

  
 
  1. /*对一个值使用typeof操作符可能返回以下某个字符串
  2.   "undefined"//如果这个值未定义
  3.   "boolean"//如果这个值是布尔值
  4.   "string"//如果这个值是字符串
  5.   "number"//如果这个值是数值
  6.   "object"//如果这个值是对象或者null
  7.   "function"//如果这个值是函数
  8. */
  9.   var int1;
  10.   var int2=true;
  11.   var int3="sun";
  12.   var int4=1;
  13.   var int5=new Object();
  14.   int5.name="zhou";
  15.   int5.age=5;
  16.   var int6=function(){
  17.   document.write(你好);
  18.   };
  19.   console.log(typeof(int1));
  20.   console.log(typeof(int2));
  21.   console.log(typeof(int3));
  22.   console.log(typeof(int4));
  23.   console.log(typeof(int5));
  24.   console.log(typeof(int6));
  25. /*输出为:
  26.   "undefined"
  27.   "boolean"
  28.   "string"
  29.   "number"
  30.   "object"
  31.   "function"
  32. */

(2), typeof use Example

 
   
  
  1. var message="some string"
  2. alert(typeof message);
  3. alert(typeof (message));
  4. alert(typeof 95);

The operand of the typeof operator can be a variable, which can be a numeric literal.

typeof is an operator rather than a function and is used in parentheses as much as possible.

Iv. Explanatory language

1. Concept: interpreted language is a language that compiles in a running environment. Conversely, a compiled language is a language that needs to be compiled by the IDE to run in the environment.

2. Features:

(1) Explanatory language:

A: Development is easier for developers. Relative to the compiled language.

B: Running speed is slower than the compiled language, which is, of course, a theoretical description. When Google developed a browser for the V8 kernel, the line was blurred.

(2) Compiled language:

A: For developers, the cost of learning is high. For example, C + +, is known as a decade to sharpen a sword language.

B: Running several fast. As I said before, this line has been blurred.

3. Summary:

When choosing a programming language, it is more important to consider the design purpose of a language than to consider a compiled or interpreted language, and what is the real need for a project to make the development process easier and faster to develop, or to improve execution efficiency. The first place to design JavaScript is to make the development process easier.

Five, Dynamic language

1, JavaScript is a dynamic language, single from the point of view of the code, dynamic language variables and functions are not specified return value type.

Vi. prototype-based object-oriented

1, the prototype-based object-oriented language features and class-based object-oriented characteristics are different.

Seven, the literal expression ability

1, the literal function is relatively excellent

Eight, function-type programming

1, JavaScript can directly support the design of the model is still procedural in nature, but because of the anonymous function, you can use the function as an object, it is also able to support functional programming.

Reference book information:

1, JavaScript programming full solution http://www.ituring.com.cn/book/1140

2. JavaScript Yu Yingjun Http://pan.baidu.com/s/1eQlegKE



From for notes (Wiz)

Basic JavaScript Concepts

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.