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:
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
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.
function test(){
var message="h1";//局部变量
}
test();
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.
function test(){
message="h1";
}
test();
console.log(message);
//输出“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)
Undefined
Null
Boolean
Number
String
2, 1 types of complex data
Object
//本质上是由一组无序名值对组成的
3. Typefo operator(1), a type of operator used to detect variable data types
//对一个值使用typeof操作符可能返回以下某个字符串
"undefined"//如果这个值未定义
"boolean"//如果这个值是布尔值
"string"//如果这个值是字符串
"number"//如果这个值是数值
"object"//如果这个值是对象或者null
"function"//如果这个值是函数
var int1;
var int2=true;
var int3="sun";
var int4=1;
var int5=new Object();
int5.name="zhou";
int5.age=5;
var int6=function(){
document.write(你好);
};
console.log(typeof(int1));
console.log(typeof(int2));
console.log(typeof(int3));
console.log(typeof(int4));
console.log(typeof(int5));
console.log(typeof(int6));
- /* Output is:
- "Undefined" js19.html:17 "boolean" "string" "Number" "Object" "function"
- */
(2), typeof use Example
var message="some string"
alert(typeof message);
alert(typeof (message));
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)