Undeclared
const foo = foo1 + 1
// foo1 is undeclaredUndefined
It’s declared but it hasn’t been assigned with any values.
let foo
let obj = {}
let arr = [1, 2, 3]
const temp = function() {
// don't return anything
}
console.log(foo, obj.name, arr[5], temp()) // undefinedNull
Null has a value. Its value is null which is a nothing value. Can be used in a situation where you need to zero out of value.
const valueIsNull = null
console.log(valueIsNull) // nullCheck for undefined
let foo
// bad idea
console.log(typeof foo) // undefined as a string
console.log(typeof temp) // undeclared, but also returns 'undefined'
// preferred way
console.log(foo === undefined) // boolean trueCheck for null
const foo = null
// terrible idea
console.log(typeof foo) // object
// preferred way
console.log(foo === null) // boolean true