Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 494
Freewind Avatar asked Sep 13 '11 17:09

Freewind


People also ask

What is the difference of js from browser to js on node JS?

JavaScript is a simple programming language that runs in any browser JavaScript Engine. Whereas Node JS is an interpreter or running environment for a JavaScript programming language that holds many excesses, it requires libraries that can easily be accessed from JavaScript programming for better use.

How JavaScript works in browser and node?

js uses Google's V8 engine to provide JavaScript runtime and employes its own event loop using the libuv library (written in c). Node follows the same callback approach like Web APIs and works in a similar fashion as the browser.

Does node uses the same JavaScript engine as Chrome?

Node uses the same JS "engine" that runs chrome. An engine in this case, is a piece of software that compiles, or "translates" your JS code into machine code; or the 0s and 1s your computer can understand.


2 Answers

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

like image 80
user113716 Avatar answered Oct 14 '22 08:10

user113716


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.

like image 31
Craig Avatar answered Oct 14 '22 07:10

Craig