当前位置:网站首页>Some features of ECMAScript

Some features of ECMAScript

2022-07-06 00:58:00 sunday2018

ECMAScript Some characteristics of

Strict mode (strict mode)

ES5 introduce . In strict mode JS The parsing and execution of will be different , Solve some ES3 Uncertain behavior in , Unsafe operation will also report errors .

Usage mode

Add the following code at the top

//  Switch JS The engine is in strict mode 
"use strict";

Specifies that the function executes in strict mode

function test() {
    "use strict";
    // ...
}

data type

ES Yes 6 Type of data :
undefined, null, boolean, number, string, object

typeof

typeof Can be used to detect the data type of variables , The returned string is

// 'undefined'  Undefined 
// 'boolean'
// 'string'
// 'number'
// 'object'  Object or null
// 'function'

 Insert picture description here

Undefined type

Undefined Variables of type have only one value , namely undefined
Use var Declare variables , But the variable is not initialized , The value of this variable is undefined.
 Insert picture description here

Null type

Null Type has only one value ,null.
If the defined variable is prepared to hold the object , It is recommended to initialize the variable to null.

Object type

Object similar Java Medium Object object , Every Object Instances of types will have Object Properties and methods in classes .

  • constructor, Save the function that creates the current object
  • hasOwnProperty(propertyName), Check whether the given property exists in the current object instance
  • isPropertypeOf(object), Check whether the incoming object is the prototype of the current object
  • propertyIsEnumerable(propertyName), Check whether the attribute can be used for-in enumeration
  • toLocalString()
  • toString()
  • valueOf()

function

No overloading , Function with the same name , The function defined later will overwrite the function defined earlier .

原网站

版权声明
本文为[sunday2018]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202140158518392.html