Working with JavaScript in Node.js
Understand how JavaScript behaves in Node.js, focusing on the global object and built-in functions like setTimeout.
When using JavaScript in the browser, we work with the window
object as the global scope, which includes methods like alert()
and properties like location
. However, in Node.js, there is no window
object because it operates outside the browser environment. Instead, Node.js uses its own global object, global
, to store globally accessible properties and functions. Functions like console.log()
and setTimeout()
are part of this global scope and can be used directly in Node.js applications.
While we can reference properties on the global
object explicitly, in most cases, we can access global properties directly without needing the global.
prefix.
Common global properties and functions
Here are a ...