JavaScript Data Types

Just like in our world there are different types of information available like a book, picture, car, movie and currency. Similarly in programming, we have data types that can show the type of data. There can be different types of data in JavaScript for example, String, Number and Boolean etc

String:

This datatype is for storing a piece of text. The text can be alphanumeric. String type values are enclosed in single quotes ‘ ‘.

In the example below we have created a variable named myString and assigned a value ‘a piece of text’ of string type using sing quote. We have used semicolon at the end to state that this is the end of line.

We can show the value of our string on a web page using JavaScript alert.

Number:

A number type of data for example 23 or 44.5o.

In the example below we have created a variable named myNumber and assigned a value 20.18 of number type.

Boolean:

It only saves two values: true / false.

In the example below we have created a variable named myBoolean and assigned a value true of Boolean type. We can show the value of our string on a web page using JavaScript alert.

Undefined:

A variable without any value.

In the example below we have created a variable named a and have not assigned any value to it.

Null:

A variable with zero value.

In the example below we have created a variable named myNull and assigned a value null. We have used semicolon at the end to state that this is the end of line.