JavaScript Tutorials


» Introduction to JavaScript

» Practice IT Editor

» JavaScript Example

» JavaScript Placement

» JavaScript Syntax

» JavaScript Statements

» JavaScript Input

» JavaScript Output

» JavaScript Comments

» JavaScript Variables

» Variables' Scope

» JavaScript Operators

» JS Expressions & Concatenation

» JavaScript Data Type

» JavaScript Numbers

» Number Object

» JavaScript Strings

» String Object

» JavaScript Booleans

» Boolean Object

» JavaScript Functions

» JavaScript Arrays

» Array Object - Properties

» Array Object - Methods

» JavaScript Objects

» JavaScript Undefined

» JavaScript Nulls


» If Statement

» If Else Statement

» JavaScript Ternary Operator

» Switch Statement


» For Loops

» While Loops

» Break & Continue

» For...In Loops

» do...while Loop


» JavaScript Functions

» Creating Functions

» Functions' Parameters

» Functions' Arguments

» Function Invocation

» The Return Keyword

» The Arguments Object

» Callback Functions

» Arrow Functions


» JavaScript Arrays

» Creating Arrays

» Accessing Arrays

» Looping Arrays

» Multi - dimensional Arrays


» JavaScript Objects

» Creating Objects

» Prototype Definition

» Accessing Objects

» The this Keyword


» Introduction to AJAX


» Introduction to JSON


» The Date Object

» Date Methods

» Timing (SetInterval & SetTimeout)


» Math Object

» Math Methods


» DOM Introduction

» Accessing HTML Elements in DOM

» Get And Change Elements' Contents & Values

» Change Styling - DOM CSS

» DOM Attributes

» JavaScript Event Listeners

» DOM Event Listeners

» JS Events


» JS Strict Mode

» JavaScript Hoisting

» JavaScript let keyword

» Reserved Keywords

» JS Best Practices

» JavaScript vs ECMAScript


» JavaScript Calculator

.. » JavaScript » Introduction » JavaScript Nulls
Share Tweet WhatsApp

JavaScript Nulls

Null is a JavaScript data type that can be assign to a variable to depict the absence of a value for that variable. When assigned to a variable, it means no value is available yet for that variable. Difference Between Null & Undefined The difference between null and undefined can be a bit confusing since both depict variables without values but then, the difference between undefined and null is, JavaScript automatically assigns the value and data type of undefined to any variable being used without a value or a variable being used which was neither declared nor assigned a value. On the other hand, null is assigned to a variable by us to denote the absence of a value for that variable. It is not automatically assigned by JavaScript rather we assign it just the way we assign numbers and string. We assign null to show we are aware of the existence of the variable without a value for it.
var x = null;
We also use null to remove or offset the value of a variable if we no longer need that value.
var arr = [1, 2, 3]; //arr contains an array
arr = null; //arr is now null or empty
Not automatically assigned by JavaScriptAutomatically assigned by JavaScript to variables that are neither declared nor assigned a value.
Data type is objectData type is undefined.
null is a reserved keyword.undefined is not a reserved keyword.
Null Object Every variable that is assigned null has an object. Nevertheless, it is an empty object which have no properties or methods that can be used in manipulating null values. Nulls' typeof() Using the typeof operator on a variable assigned the value, null will return object but then, it is an empty object. According to JS history, null is an object by mistake but then, you may wonder why it hasn't been corrected? Well, it is because it will disrupt a lot of JavaScript programs on the web. SUMMARY
  1. Null is a value assigned to a variable to depict absence of a value.
  2. The typeof operator will return null when used on null.
Take a short quiz on JavaScript Nulls.
Ask a question or tell us if JavaScript Nulls is easy or not.

Join our 1,090 subscribers to receive tutorials' updates!

  We won't spam your mail box. We hate it.

StackBeginner 2021 © Joseph Omamode