JavaScript

coding learning websites codepractice

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?


JavaScript

online coding class codepractice

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

Go Back Top