If you wish to shred a variable of its assigned value, you can simply assign ‘null’ to it.
var myVar = null;
Simple example code.
<!DOCTYPE html> <html> <body> <script> const a = null; console.log(typeof a); console.log(a); </script> </body> </html>
When checking for
undefined, beware of the differences between equality (==) and identity (===) operators, as the former performs type-conversion.
typeof null // "object" (not "null" for legacy reasons) typeof undefined // "undefined" null === undefined // false null == undefined // true null === null // true null == null // true !null // true isNaN(1 + null) // false isNaN(1 + undefined) // true
Do comment if you have any doubts or suggestions on this JS null topic.
Note: The All JS Examples codes are tested on the Firefox browser and the Chrome browser.
OS: Windows 10
Code: HTML 5 Version
Degree in Computer Science and Engineer: App Developer and has multiple Programming languages experience. Enthusiasm for technology & like learning technical.