What is null/nil in JavaScript and how to work with it?
Hello everyone! I started learning JavaScript (Node.js) and encountered confusion with the terms null and nil. In other languages, like Ruby or Go, nil is the standard "nothing" value. But in JS I only see null and undefined. However, I've heard that some people use nil in Node.js code. Please tell me, does nil exist in JavaScript as a separate type? Or is it just an alias for null?
I tried writing a simple script to check:
let a = null;
let b = undefined;
console.log(a === b); // false
console.log(typeof a); // object
console.log(typeof b); // undefined
// Attempt to use nil
let c = nil; // ReferenceError: nil is not defined