JavaScript

JS Basics

JS Variables & Operators

JS Data Types & Conversion

JS Numbers & Math

JS Strings

JS Dates

JS Arrays

JS Control Flow

JS Loops & Iteration

JS Functions

JS Objects

JS Classes & Modules

JS Async Programming

JS Advanced

JS HTML DOM

JS BOM (Browser Object Model)

JS Web APIs

JS AJAX

JS JSON

JS Graphics & Charts

JavaScript

JS Basics

JS Variables & Operators

JS Data Types & Conversion

JS Numbers & Math

JS Strings

JS Dates

JS Arrays

JS Control Flow

JS Loops & Iteration

JS Functions

JS Objects

JS Classes & Modules

JS Async Programming

JS Advanced

JS HTML DOM

JS BOM (Browser Object Model)

JS Web APIs

JS AJAX

JS JSON

JS Graphics & Charts

JS Data Types


📘 JavaScript Data Types – Types of Values in JavaScript

In JavaScript, data types define the type of data a variable can hold. JavaScript is dynamically typed, meaning variables can hold any type of value at any time.


🔹 JavaScript Has Two Main Categories of Data Types:

✅ 1. Primitive Data Types
  • These are immutable and hold single values.

Data Type Example
String "Hello", 'World'
Number 42, 3.14
Boolean true, false
Null null
Undefined undefined
BigInt 12345678901234567890n
Symbol Symbol("id")

✅ 2. Non-Primitive (Reference) Data Types
  • These hold collections of values or complex entities.

Data Type Example
Object {name: "Alice", age: 25}
Array ["apple", "banana", "cherry"]
Function function greet() {}
Date new Date()

🔍 typeof Operator

You can check the data type of a value using typeof:

typeof "Hello"     // "string"
typeof 123         // "number"
typeof true        // "boolean"
typeof undefined   // "undefined"
typeof null        // "object" ✅ (known JS quirk)
typeof [1, 2, 3]   // "object"
typeof {a: 1}      // "object"
typeof function(){}// "function"

💡 Special Notes

  • null is of type object (this is a bug in JavaScript)

  • Arrays and functions are technically objects

  • Data types can change dynamically during execution


Practice Questions

Q1. How do you declare a string variable named greeting with the value "Hello World"?

Q2. How do you declare a number variable price with the value 199.99?

Q3. How do you check if a variable isActive is a boolean using the typeof operator?

Q4. How do you define an array fruits containing "apple", "banana", and "mango"?

Q5. How do you create an object person with properties name: "John" and age: 30?

Q6. How do you define a variable discount with the value null and check its type using typeof?

Q7. How do you define a function greet() that prints "Hi" and check its type?

Q8. How do you assign a BigInt value 12345678901234567890n to a variable bigNum?

Q9. How do you declare an undefined variable named result?

Q10. How do you create a variable now and assign the current date and time using Date() object?


JS Data Types Quiz

Q1: Which of the following is a primitive data type in JavaScript?

A. Object
B. Array
C. String
D. Function

Q2: What is the result of typeof null?

A. "null"
B. "undefined"
C. "object"
D. "boolean"

Q3: Which keyword is used to declare a variable without assigning a value?

A. var
B. undefined
C. null
D. let

Q4: Which operator is used to check the data type of a variable?

A. check()
B. typeof
C. type()
D. isType

Q5: What will typeof [1,2,3] return?

A. "array"
B. "object"
C. "list"
D. "collection"

Q6: Which of the following is NOT a primitive data type?

A. Boolean
B. Object
C. String
D. Number

Q7: What is the output of typeof function(){}?

A. "object"
B. "function"
C. "method"
D. "undefined"

Q8: Which of these values is of type Boolean?

A. 0
B. "true"
C. true
D. null

Q9: Which of the following is the correct way to define a BigInt?

A. 1234b
B. BigInt(1234)
C. 1234n
D. int(1234)

Q10: Which statement is true about JavaScript data types?

A. JavaScript is statically typed
B. You cannot change data types once set
C. JavaScript is dynamically typed
D. JavaScript supports only primitive types

Go Back Top