0% found this document useful (0 votes)
4 views15 pages

2. JavaScript DataTypes

The document provides an overview of JavaScript data types, detailing the eight basic types: String, Number, BigInt, Boolean, undefined, null, Symbol, and Object. It explains JavaScript's dynamic and weak typing, where variables can change types and implicit type conversion occurs. Additionally, it highlights the distinction between primitive and non-primitive data types, emphasizing the immutability of primitive values and the mutability of objects.

Uploaded by

Arofath
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views15 pages

2. JavaScript DataTypes

The document provides an overview of JavaScript data types, detailing the eight basic types: String, Number, BigInt, Boolean, undefined, null, Symbol, and Object. It explains JavaScript's dynamic and weak typing, where variables can change types and implicit type conversion occurs. Additionally, it highlights the distinction between primitive and non-primitive data types, emphasizing the immutability of primitive values and the mutability of objects.

Uploaded by

Arofath
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 15

JavaScript

Data Types
Contents

1. Overview

2. String

3. Number

4. BigInt

5. Boolean

6. null

7. Object

2
1. Overview

Data types and Data Structure

Programming languages all have built-in data structures,

Dynamic and Weak Typing

JavaScript is a dynamic language with dynamic types.


let foo = 42; // foo is8 now a number
foo = "bar"; // foo is now a string
foo = true; // foo is now a boolean

3
1. Overview

JavaScript is also a weakly typed language, which means it allows implicit type
conversion when an operation involves mismatched types, instead of throwing
errors.
const foo = 42; // foo is a number
const result = foo + "1"; // JavaScript coerces foo to a
string, so it can be concatenated with the other operand
console.log(result); // 421

Primitive Value

In JavaScript, primitive values are immutable — once a primitive value is created,


it cannot be changed. By contrast, objects and arrays are mutable by default —
their properties and elements can be changed without assigning a new value. 4
1. Overview

• Data types describe the different types or kinds of data that will be storing
in variables.

• In JS, there are 8 basic data types:


Data Types Description Example
String Represents textual data ‘hello’, ‘Chan Dara’, …
Number An integer or a floating-point number 3, 3.14, 3e-2, …
BigInt An integer with arbitrary precision 900719925124740999n, 1n, …
Boolean Any of two values: true or false true and false
undefined A data type whose variable is not initialized let a
null Denotes a null value let a = null
Symbol Data type whose instances are unique and immutable let a = Symbol(‘hello’)
Object Key-Value pairs of collection of data let student = { }
5
1. Overview (cont.)

• All data types except Object are primitive data types, whereas Object is non-
primitive.

• Example:

const x = 5

const y = “Hello”
5 is an integer data.
"Hello" is a string data.

Conceptually, undefined indicates the absence of a value,


while null indicates the absence of an object
6
1. Overview (cont.)

• JavaScript is a dynamically types (loosely typed) language.

• JavaScript automatically determines the variables’ data type for you.

• Example:
// data is of undefined type
let data;
// data is of integer type
data = 5;
// data is of string type
data = "JavaScript Programming";

• To find the type of a variable, you can use the typeof operator.
// data is of undefined type
typeof (variableName);

7
2. String

• String is used to store text and they are surrounded by quotes:


• Single Quote (‘ ’)
• Double Quote (“ ”)
• Backtick (` `)

8
3. Number

• Number represents integer and floating numbers.

• A number type can also be +Infinity, -Infinity, and NaN (not a number).

9
4. BigInt

• In JS, Number type can only represent numbers less than (253-1) and more
than –(253-1).

• A BigInt number is created by appending n to the end of an integer.


BigInt was
introduced in the
newer version of
JavaScript and is
not supported by
many browsers
including Safari.

10
5. Boolean

• Boolean represents one of two values: true or false.

11
6. undefined

• The undefined data type represents value that is not assigned.

12
7. null

• In JS, null is a special value that represents empty or unknown value.

• Note: null is not the same as NULL or Null.

13
8. Object

• An object is a complex data type that allows us to store collections of data.

14
Thank you
Perfect Practice, Does Perfect Thing

15

You might also like