简体   繁体   中英

What's the syntax difference of JavaScript between node.js and browsers?

Browsers support JavaScript, and Node.js supports it too. I want to know if there any syntax difference between them?

Node uses Google V8 , which implements the ECMAScript standard (link to non official annotated copy) .

How it differs from browsers will depend on which browser (and version) you're talking about.


For example, Mozilla browsers implement JavaScript (which is an implementation and superset of ECMAScript ).

JavaScript includes:

  • for each - in loops
  • destructuring assignment
  • let expressions
  • array comprehensions

...among other enhancements that utilize non ECMAScript standard syntax. These are all part of JavaScript , but not currently part of the ECMAScript standard.

(Of the 4 items listed, the last 3 are proposals for the next ECMAScript version.)

No. The Syntax is exactly the same. There are differences in the apis however. The standard browser dom is not available in node but it has additional apis found at nodejs.org . Any syntax differences are due to quirks in browsers.

不会。语法完全相同,但您正在使用它提供不同的环境 - 例如,您没有DOM并且具有用于文件系统访问和套接字的API。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM