Freewind
Freewind

Reputation: 198188

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?

Upvotes: 6

Views: 8084

Answers (3)

user113716
user113716

Reputation: 322452

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.)

Upvotes: 14

shesek
shesek

Reputation: 4682

No. The syntax is exatcly the same, but you're working it provides with different environment - for example, you don't have DOM and have API for file system access and sockets.

Upvotes: 1

Craig
Craig

Reputation: 7671

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.

Upvotes: 8

Related Questions