Basic JavaScript Concepts (i)

Source: Internet
Author: User

First, Strict mode 1, ECMASCRIPT5 introduced the concept of strict mode (strict mode). The intent is to define a different parsing and execution pattern for JavaScript.2.Different in strict mode:    (1),Some indeterminate behavior will be dealt with.     (2),exceptions are also thrown for certain unsafe operations.     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:
 
   
  
  1. IE10+
  2. Firefox 4+
  3. Safari 5.1+
  4. Opera 12+
  5. Chrome

Variables 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 hold.
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.
 
   
  
  1. function test(){
  2. var message="h1";//局部变量
  3. }
  4. test();
  5. console.log(message);//报错
    (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. message="h1";
  3. }
  4. test();
  5. console.log(message);
  6. //输出“hi”
            (3), when the var operator is omitted, causes the message to become 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. Iii. 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
 
   
  
  1. Object
  2. //本质上是由一组无序名值对组成的
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"//如果这个值是函数
  
 
  1. var int1;
  2. var int2=true;
  3. var int3="sun";
  4. var int4=1;
  5. var int5=new Object();
  6. int5.name="zhou";
  7. int5.age=5;
  8. var int6=function(){
  9. document.write(你好);
  10. };
  11. console.log(typeof(int1));
  12. console.log(typeof(int2));
  13. console.log(typeof(int3));
  14. console.log(typeof(int4));
  15. console.log(typeof(int5));
  16. console.log(typeof(int6));
  17. /* Output is:
  18. "Undefined" js19.html:17 "boolean" "string" "Number" "Object" "function"
  19. */
(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.



From for notes (Wiz)

Basic JavaScript Concepts (i)

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.