JavaScript Non Primitive Datatypes

Non - Primitive Datatypes

Undefined :

When the variable is used to store “no value”, primitive data type undefined is used.

undefined is a data type in JavaScript that has a single value also termed as undefined.

undefined value represents “no value”.

Any variable that has not been assigned a value during declaration will be automatically assigned with the value undefined.

JS Undefined datatypes

We can make the JavaScript variable empty by assigning the value undefined.

JS Undefined datatypes 2

Object :

The variables in JavaScript may not always hold only individual values which are having one of the primitive data types.

There are times when we want to store a group of values inside a variable.

JavaScript gives non-primitive data type Object, to implement this.

Objects in JavaScript are a collection of properties and are represented in the form of [key-value pairs].

The key of a property is a string or a symbol and should be a legal identifier.

The value of a property can be any JavaScript value like Number, String, Boolean or another object.

JavaScript provides the number of built-in objects as a part of the language and user-defined JavaScript objects can be created using object literals.

JS Object syntax

null :

Next in the list is data type null in JavaScript that has a single value which is termed as null.

null value represents “no object”.

If you are wondering why would we need such a data type, the answer is JavaScript variable intended to be assigned with the object at a later point in the program can be assigned null during the declaration.

JS Null Syntax

If required, JavaScript variable can also be checked if it is pointing to a valid object or null.

For example,

#Non_Primitive_Datatypes_in_javascript #non_primitive_data_types_in_javascript #primitive_and_non_primitive_data_types_in_javascript

(New page will open, for Comment)

Not yet commented...