JavaScript Data Types

The data types in JavaScript are divided into the following:

  • Primitive Data Types: String, Number, Boolean, Undefined, Null,
  • Non-Primitive: Object, Array

Let us understand the data types one by one with examples:

JavaScript String Data-Type

The string data type in JavaScript represents a sequence of characters, for example, “amit”, “john”, etc.

Let us see an example to work on the string data type in JavaScript:

Output

JavaScript data types string

JavaScript Number Data-Type

The number data type in JavaScript not only represents integers but float values as well.

Let us see an example to work on number data type in the form of integer number:

Output

JavaScript data types number

Let us see an example to work on number data type in the form of floating-point numbers:

Output

JavaScript data types floating point number

JavaScript Boolean Data-Type

The Boolean data type in JavaScript represents the Boolean values i.e. true or false.

Let us see an example to work on boolean data type in JavaScript:

Output

JavaScript data types boolean

JavaScript Undefined Data-Type

The Undefined data type is used to represent an undefined value.

Let us see an example to work on undefined data type in JavaScript:

Output

JavaScript data types undefined

JavaScript Null Data-Type

The Null data type is used to represent null. The null means no value.

Let us see an example to work on null data type in JavaScript:

Output

To view the output on the console, press F12 on the web browser. Then, click the Console tab as shown below:

JavaScript data types null

JavaScript Object Data-Type

The object data type represents name:value pairs, surrounded with curly braces.

Let us see an example to work on object data type in JavaScript:

Output

To view the output on the console, press F12 on the web browser. Then, click the Console tab as shown below:

JavaScript data types object

JavaScript Array Data-Type

The Array data type represents more than one value in a single variable. The items in the array are separated by commas. It is enclosed by square brackets. The index of an array begins from 0.

Let us see an example to work on array data type in JavaScript. We will declare an array and display all the items:

Output

JavaScript data types array example1

Let us see an example to display specific array items:

Output

JavaScript data types array example2

JavaScript Variables
JavaScript - Run First Script
Studyopedia Editorial Staff
contact@studyopedia.com

We work to create programming tutorials for all.

No Comments

Post A Comment

Discover more from Studyopedia

Subscribe now to keep reading and get access to the full archive.

Continue reading