DEV Community

Cover image for Javascript: Data type and variables
Temitope Agbaje
Temitope Agbaje

Posted on

Javascript: Data type and variables

Data types are concepts to be able to operate on variables.
JavaScript variables can hold Data types like Strings, numbers, arrays, and so on.

Strings
Strings are written in double quotes(" ") or single quotes(' ').
Alt Text

In the image below..you can use a double quote and single quote interchangeably or when using two double quotes or a single quote in a sentence, a backslash can be used in front.
Alt Text

Number
For the number data type, It is either a negative or a positive number. It can also be a decimal number.
Alt Text

Booleans
In boolean, It is either true or false, Yes or no, off or on.
Alt Text

Arrays
It is used to store a list of data. Arrays are written using square brackets [ ].
Alt Text
An array can be written inside another array.Arrays can be accessed by their index. Every array has an index that starts with 0.

Alt Text

Objects
The object is a data type that allows the storage of collections of data. They are denoted using square brackets { }.
Alt Text

To access the data of an object: ObjectName.keyName
Alt Text

Undefined
If a variable has been declared but has not been assigned a value, has the value undefined.
Alt Text

Top comments (0)