Home > Web Front-end > Front-end Q&A > Is ecmascript an interpreter?

Is ecmascript an interpreter?

青灯夜游
Release: 2022-01-05 10:52:29
Original
1473 people have browsed it

ecmascript is the interpreter. ecmascript is a script programming language standardized by Ecma International through ECMA-262. It is an interpreter and is responsible for translation. It is the core part of the js language and describes the syntax and basic objects of the js language.

Is ecmascript an interpreter?

The operating environment of this tutorial: Windows 7 system, ECMAScript version 6, Dell G3 computer.

A complete JavaScript implementation consists of the following 3 different parts:

  • Core (ECMAScript): The core part of the language, which describes the language syntax and basic objects.

  • Document Object Model (DOM): Web page document operation standard, describing methods and interfaces for processing web page content.

  • Browser Object Model (BOM): The basis for client and browser window operations, describing the methods and interfaces for interacting with the browser.

ECMAScript (es): Responsible for translation, the core interpreter of js.

ECMAScript defined by ECMA-262 is an internationally recognized standard scripting language specification that has no dependency on web browsers. The ECMA-262 standard mainly stipulates that the language consists of the following components:

  • Syntax

  • Variables and data types

  • Keywords and reserved words

  • Operators

  • Control statements

  • Object

ECMAScript version 5.0 was officially released in 2009. For a long time, JavaScript was used in accordance with the 5.0 standard. In 2015, ECMAScript 6 was released as an official version, officially called ECMAScript 2015. ECMAScript defines all properties, methods and objects of the scripting language. Therefore, you must follow the ECMAScript standard when coding web client scripts.

JS data types

5 basic data types: Undefined, Null, Boolean, Number, String, Symbol (new in es6)

1 3 complex types: object

5 reference types: Array, Object, Function, Date, RegExp

3 basic packaging types: Boolean, Number, String

2 Single built-in object: Global, Math

1. Four ways to determine data type

typeof

const a = ""
console.log(typeof(a)) => String
 
const b = 1
console.log(typeof(b)) => Number
 
const c
console.log(typeof(c)) =>Undefined
 
const d = []
console.log(typeof(d)) => Object
 
const e = {}
console.log(typeof(e)) =>Object
 
const f = null
console.log(typeof(f)) =>Object  //null 作为尚未创建的对象
Copy after login

instanceof

This method is only suitable for determining the object type

const arr = [] 
console.log(arr instanceof Array)=> true
 
console.log(null instanceof Object) ---> false
 
console.log([function] instanceof Object | Function)  --> true
Copy after login

Object.prototype.toString.call()

This method can detect all data types and is recommended. Because toString is the prototype method of Object, and Array Function, etc. are all instances of Object. All have overridden the toString method. What is returned is a string of type

Object.prototype.toString.call(null)  =>  [object Null]
 
Object.prototype.toString.call(Math) => [object Math]
 
Object.prototype.toString.call(function(){}) => [object Function]
 
Objdec.prototype.toString.call(new Date)  => [object Date]
 
Object.prototype.toString.call(Symbol())  => [object Symbol]
 
Object.prototupe.toString.call(undefined)  => [object Undefined]
 
Object.prototype.toString.call(123)  => [object Number]
 
Object.prototype.toString.call(true) => [object Boolean]
 
Object.prototype.toString.call('123') => [object String]
 
Object.prototype.toString.call({})    => [object Object]
 
Object.prototype.toString.call([])    => [object Array]
Copy after login

constructor

Determine the constructor of the object.

1. null is the starting point of the js prototype chain, there is no constructor

2. undefined has no constructor

3. [].constructor === Array --- > true

【Related recommendations: javascript learning tutorial

The above is the detailed content of Is ecmascript an interpreter?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template