Comprehensive Overview of JavaScript Data Types and Their Usage
Explore JavaScript's primitive and non-primitive data types, including strings, numbers, booleans, objects, arrays, and functions, with examples and the use of the typeof operator.
Introduction
• What areData Types?
– Define the type of data a variable can hold
– JavaScript is dynamically typed
Prepared By: Kale J. N.
3.
Two Categories
• JavaScriptdata types are divided into:
– 1. Primitive Data Types
– 2. Non-Primitive (Reference) Data Types
Prepared By: Kale J. N.
4.
Primitive Data Types
•- Immutable and hold single values
• Types include:
– String
– Number
– Boolean
– Undefined
– Null
– BigInt
– Symbol
Prepared By: Kale J. N.
5.
String
• let name= "Sai";
– Textual data enclosed in quotes
– Example: "Hello", 'A', `Backtick`
Prepared By: Kale J. N.
6.
Number
• let age= 25;
• let price = 99.99;
• Integers and floating-point
• Special values: Infinity, -Infinity, NaN
Prepared By: Kale J. N.
7.
Boolean
• let isStudent= true;
• Only two values: true or false
• Used in conditions
Prepared By: Kale J. N.
8.
Undefined and Null
•let x; // undefined
• let y = null; // null
• Undefined: declared but not assigned
• Null: explicitly no value
Prepared By: Kale J. N.
9.
BigInt
• let big= 12345678901234567890n;
• BigInt: for very large integers
Prepared By: Kale J. N.
10.
Non-Primitive Data Types
•Hold collections or complex entities
• Types:
– Object
– Array
– Function
Prepared By: Kale J. N.
11.
Object Example
let person= {
name: "John",
age: 30
};
- Key-value pairs
- Mixed data types
Prepared By: Kale J. N.
12.
Array Example
let fruits= ["Apple", "Banana", "Mango"];
- Ordered list
- Can store different types
Prepared By: Kale J. N.