Type something to search...

JavaScript Data Types

JavaScript Data Types

JavaScript has several data types that can be categorized into two groups: primitive and non-primitive.

Primitive Data Types

  1. String: Text data (e.g., "Hello", 'World').
  2. Number: Numeric data (e.g., 42, 3.14).
  3. Boolean: Logical values (true or false).
  4. Undefined: A variable that has been declared but not assigned a value.
  5. Null: Represents an empty or non-existent value.

Non-Primitive Data Types

  1. Object: A collection of key-value pairs.
  2. Array: A list of values.

Example

let name = "Alice"; // String
let age = 30;       // Number
let isStudent = true; // Boolean
let address;        // Undefined
let emptyValue = null; // Null

Checking Data Types

You can check the type of a variable using the typeof operator:

let value = "Hello";
console.log(typeof value); // Output: string

Type Conversion

JavaScript allows you to convert data types:

let num = "42";
let convertedNum = Number(num); // Converts string to number
console.log(typeof convertedNum); // Output: number

Next: Operators →