Example - Dynamically typed
String is a data type which is used to store texts, character or sentences. It is created by enclosing text data in single or double quotes.
boolean is a data type which has two values true and false.
boolean is used for yes-no, on-off purposes.
undefined are the variables which are defined but have not been assigned value to them.
null has only one value, the null.
null is different from
undefined. null is nor equal to "" neither equal to 0.
null means there is nothing.
Symbol is another primitive data type. It can be created by calling Symbol().
symbols are unique every time it is invoked.
non-primitive data types are object based or methods. Other data types are called
primitive because they can only hold one type of data but
non-primitive data types can hold different types of data as a collection. Basically there are three data type in this
object is a non-primitive data type; it holds data in the form of key-value pairs. It stores collections of different types of data.
The property key is always a string, but the value could have any data type.
Here is a simple example to show how to create objects and use them.
Array is a non-primitive data type which is used to store multiple values in a single variable which is accessed through index value. Each value stored in the
array has a position value which starts with 0, known as index of array.
To get array value we write name_of_array[position]. So if name the is arr, then the first value will be
arr, second value will be
arr and so on.
Here is an example of an array. We will learn in detail in the coming chapter.
function can be assigned to some variable. See example below. We will learn about function in upcoming lessons.
typeof a or
typeof operator is used when you need to get data type of some variable to perform some task.
typeof operator gives some unexpected results shown below so be careful when using it.