What is the difference between nodejs and js?

Posted Jun 28, 20202 min read

Node.js is a JavaScript running environment based on Chrome V8 engine. JavaScript is a literal scripting language. It is a dynamically typed, weakly typed, prototype-based language.

js(JavaScript) is a high-level, interpreted programming language; it is a prototype-based, function-first language, a multi-paradigm language that supports object-oriented programming, imperative programming, and functional programming .

Node.js is a JavaScript running environment based on the Chrome V8 engine. It is a development platform that allows JavaScript to run on the server side. It makes JavaScript a scripting language on a par with server-side languages such as PHP, Python, Perl, and Ruby.

The difference between node.js and js:

  1. node.js is the platform, and Js is the programming language;

  2. js is a client-side programming language, which requires a browser s JavaScript interpreter for interpretation and execution;

  3. node.js is a platform built on the basis of Chrome JavaScript runtime, it is a running environment that encapsulates the Google V8 engine;

  4. node.js is to encapsulate the browser's interpreter as a server running platform, use JavaScript-like structure syntax to program, and run on node.js.

  5. The composition of node.js and js is different:

JavaScript:

  • ECMAScript(language foundation, such as:syntax, data type structure, and some built-in objects)
  • DOM(some methods of manipulating page elements)
  • BOM(some methods of operating the browser)

Node.js:

  • ECMAScript(language foundation, such as:syntax, data type structure, and some built-in objects)
  • OS(operating system)
  • file(file system)
  • net(network system)
  • database
  1. Different top-level objects

The top-level object in JS is a window object, but there is no window object in node, and the top-level object in node is a global object. This is the difference between the two.

In the window object, defining a global variable can be accessed through Window, but cannot be accessed through the global object in node, such as:

var a=100;
console.log(global.a);

This way the output is:

undefined

For the above example, because the variable defined in node is an object in the module, not a global global variable, the result is undefined.