Javascript - Null

About

null is a javascript data type that is unfortunately reported as an object by the typeof operator.

null means no object value, whereas undefined means no value.

typeof null returns object, and not null, despite Null being a type of its own.

x=null;
console.log(typeof(x));

Management

typeof

Confusingly, typeof reports the type of null as “object”, but the ECMA-Script standard describes it as a distinct type.

console.log("null has the type "+typeof(null));

Nullish coalescing operator (??)

The Nullish coalescing operator (??) is a short-circuiting operator meant to handle default values.

nullish means that the value is equal to null or undefined.

Syntax:

leftOperand ?? RightOperand

where:

  • If leftOperand is not nullish, it evaluates to leftOperand .
  • Otherwise, it evaluates to RightOperand.

Example:

const enable = props.enabled ?? true;

https://v8.dev/features/nullish-coalescing

Documentation / Reference





Discover More
Javascript - Primitive Data Type

Javascript has 6 primitive data type. string number boolean null undefined symbol Except for null and undefined, all primitive values have object equivalents that wrap around the primitive...
Javascript - Type

Type in Javascript Javascript is not static typed but it exist Javascript wrapper language that implements it. See Only values have types in JavaScript; variables are just simple containers for those...



Share this page:
Follow us:
Task Runner