JavaScript Data Types

Primitive Data Types

JavaScript has several primitive data types that represent simple values.

Tutorials dojo strip

1. Number

The number data type represents both integer and floating-point numbers.

JavaScript

2. String

The string data type is used to represent text. Strings are enclosed in single quotes ('), double quotes ("), or backticks (`).

JavaScript

3. Boolean

The boolean data type represents a logical value: true or false.

JavaScript

4. Undefined

A variable that has been declared but not assigned a value is of type undefined.

JavaScript

5. Null

The null data type represents an intentional absence of any object value. It is treated as an object type, but this is actually a bug in JavaScript.

JavaScript

6. Symbol

The symbol data type is used to create unique identifiers for objects.

JavaScript

Complex Data Type

JavaScript also has a complex data type known as Object.

Object

Objects are collections of key-value pairs. They can store multiple values as properties.

JavaScript

JavaScript Data Types Example Code

Explanation of Code:

  • Number: Declares a variable age with a numeric value.
  • String: Declares a variable name with a string value.
  • Boolean: Declares a variable isStudent with a boolean value.
  • Undefined: Declares a variable city without assigning a value.
  • Null: Declares a variable car with a null value.
  • Symbol: Declares a variable sym with a unique symbol.
  • Object: Declares a variable person with properties.
HTML

JavaScript Labs

Tutorials dojo strip