6

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

1
  • Strictly speaking, syntax are technically just rules how the tokens can be and those should be the same for everything that claims to be ECMAScript. But some people (especially those who aren't up to their knees in compiler technology) also include how typical usage of the major APIs looks like (on a higher level) in "syntax". Which one are you talking about? Commented Sep 13, 2011 at 17:15

3 Answers 3

14

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

Sign up to request clarification or add additional context in comments.

9 Comments

More specifically it implements versions of V8
@Raynos: Thanks, I just caught that flub. :)
If he really needs DOM functionally in Node.JS he can use github.com/tmpvar/jsdom (GH is having issue atm).
More specifically node 0.4.9-0.4.11 use V8 3.1.8.25
@patrick_dw the distinction is worth illustration, I'd just recommend mentioning that JavaScript is mozillas implementation and not an alternative word for ECMAScript.
|
8

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.

Comments

1

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.