Download as pdf or txt
Download as pdf or txt
You are on page 1of 4

Javascript inbuit objects

Frequency 4

JavaScript provides a variety of built-in objects that are used to perform a range
of tasks and operations. These objects are foundational to the language and are
categorized into several groups based on their functionality. Here's an overview of
some of the key built-in objects in JavaScript:

Primitive Objects:
1. Number: Represents numerical values, both integers and floating-point
numbers.

Example:

const num = 42;


const pi = 3.14;

2. String: Represents sequences of characters.

Example:

const greeting = "Hello, world!";

3. Boolean: Represents a logical true or false value.

Example:

const isTrue = true;


const isFalse = false;

4. BigInt: Represents large integers that are outside the safe integer range of the
Number type.

Example:

Javascript inbuit objects 1


const bigNum = 1234567890123456789012345678901234567890
n;

5. Symbol: Represents unique identifiers for object properties.

Example:

const sym1 = Symbol("key1");


const sym2 = Symbol("key2");

Composite Objects:
1. Array: Represents ordered collections of values.

Example:

const arr = [1, 2, 3, 4, 5];

2. Object: Represents collections of key-value pairs.

Example:

const person = {
name: "Alice",
age: 30,
isStudent: false
};

3. Function: Represents functions and methods.

Example:

function greet(name) {
return `Hello, ${name}!`;
}

4. Date: Represents dates and times.

Javascript inbuit objects 2


Example:

const today = new Date();

5. RegExp: Represents regular expressions for pattern matching in strings.

Example:

const regex = /hello/;

Utility Objects:
1. Math: Provides mathematical constants and functions.

Example:

const sqrt = Math.sqrt(16); // Returns 4

2. JSON: Provides methods for working with JSON data.

Example:

const jsonData = '{"name":"Alice","age":30}';


const data = JSON.parse(jsonData);

Error Objects:
1. Error: Represents a generic error.

Example:

throw new Error("An error occurred");

2. TypeError: Represents an error due to incorrect data type usage.

Example:

const num = 42;


try {

Javascript inbuit objects 3


num();
} catch (e) {
console.log(e instanceof TypeError); // true
}

3. SyntaxError: Represents a syntax error in JavaScript code.

Example:

try {
eval('let');
} catch (e) {
console.log(e instanceof SyntaxError); // true
}

4. RangeError: Represents an error when a value is outside the expected range.

Example:

try {
const range = Math.pow(10, 1000);
} catch (e) {
console.log(e instanceof RangeError); // true
}

These built-in objects form the basis of JavaScript programming and are widely
used in various operations such as arithmetic, string manipulation, date and time
handling, and error handling.

Javascript inbuit objects 4

You might also like