JavaScript is closely related to the concept of environments, with options like browsers and Node.js available for running JS code (CoffeeScript compiles to JavaScript).
When using JavaScript in a browser, the global object is referred to as window
. However, in Node.js, the global object is simply global
.
Some methods are common in both environments, such as core JavaScript methods...
String.prototype
methods
Array.prototype
methods
Object.prototype
methods
- and more.
...as well as specific window
methods like setInterval
or setTimeout
.
However, functions like window.alert
are not available in command-line interfaces (CLIs). To incorporate this feature in Node, you can utilize a package like alert-node by running npm i alert-node
.
JavaScript
// alert.js
var alert = require('alert-node');
alert('Hello');
Command: node alert.js
CoffeeScript
# alert.coffee
alert = require 'alert-node'
alert 'Hello'
Command: coffee alert.coffee