All created, without any known values, new variables should contain null.
This rule helps to easily distinguish non-existent properties and variables from cleaned or already created but not have
value.
Object.prototype.hasOwnProperty() cannot be conveniently applied to large objects.
It also helps maintain consistency with the server side.
In queries "undefined" and "null" have different meanings:
- "undefined" - Value not set
- "null" - The value is set as void
MDN Web Docs - null
eslint - init-declarations
Combination of:
eslint - no-undefined
eslint - no-undef-init
let a;
const obj = {
c: undefined,
};
console.log(a) // undefined
console.log(b) // undefined
console.log(obj.c) // undefined
console.log(obj.d) // undefinedlet a = null;
const obj = {
c: null,
};
console.log(a); // null
console.log(b); // undefined
console.log(obj.c); // null
console.log(obj.d); // undefinedBack to Code Guide - JavaScript
Copyright © 2017 Stanislav Kochenkov