Menu
Posted At Fri, Oct 20, 2023 7:13 AM

JavaScript Built-in Objects

Listen | 3 min read

Table of Contents

1. Introduction to JavaScript Built-in Objects
2. What Are JavaScript Built-in Objects?
3. The Object Object
4. The Array Object
5. The String Object
6. The Number Object
7. The Boolean Object
8. The Function Object
9. The Date Object
10. The Math Object
11. The JSON Object
12. Conclusion

1. Introduction to JavaScript Built-in Objects

JavaScript offers a variety of built-in objects that provide essential functionality for working with data and manipulating the DOM. Understanding these objects is crucial for effective web development.

2. What Are JavaScript Built-in Objects?

Built-in objects in JavaScript are pre-defined objects that offer various methods and properties. They simplify common tasks such as working with strings, arrays, numbers, dates, and more.

3. The Object Object

The Object object is the most fundamental in JavaScript, serving as the base for all other objects. You can create custom objects, define properties, and add methods using this object.

const person = new Object();
person.name = 'John';
person.age = 30;

console.log(person.name); // Outputs: John

4. The Array Object

Arrays are used to store collections of data. They come with built-in methods for adding, removing, and manipulating elements.

const fruits = ['apple', 'banana', 'cherry'];

console.log(fruits.length); // Outputs: 3

5. The String Object

The String object is used for working with strings, offering various methods for string manipulation.

const greeting = 'Hello, World!';
const upperCaseGreeting = greeting.toUpperCase();

console.log(upperCaseGreeting); // Outputs: HELLO, WORLD!

6. The Number Object

The Number object helps work with numeric values, providing methods for precision control and formatting.

const pi = 3.14159;
const fixedPi = pi.toFixed(2);

console.log(fixedPi); // Outputs: 3.14

7. The Boolean Object

Boolean objects help handle true or false values and offer useful methods for logical operations.

const isJavaScriptFun = true;
const isLearningEasy = false;

console.log(isJavaScriptFun && isLearningEasy); // Outputs: false

8. The Function Object

Functions in JavaScript are also objects. They can be assigned to variables, passed as arguments, and returned from other functions.

const add = function(a, b) {
  return a + b;
};

console.log(add(5, 3)); // Outputs: 8

9. The Date Object

The Date object simplifies date and time handling, allowing you to manipulate dates, set intervals, and more.

const today = new Date();
const year = today.getFullYear();

console.log(year); // Outputs the current year

10. The Math Object

The Math object provides a collection of mathematical constants and functions for performing complex calculations.

const circleArea = Math.PI * Math.pow(5, 2);

console.log(circleArea); // Outputs the area of a circle with a radius of 5

11. The JSON Object

JSON (JavaScript Object Notation) is a lightweight data interchange format. The JSON object offers methods for parsing and stringifying JSON data.

const person = { name: 'John', age: 30 };
const jsonPerson = JSON.stringify(person);

console.log(jsonPerson); // Outputs: {"name":"John","age":30}

12. Conclusion

JavaScript built-in objects are powerful tools that simplify common tasks in web development. Knowing how to use these objects will greatly enhance your coding capabilities and allow you to create more robust applications.

Next one is learning about JavaScript Typeof Operator.

Click this link! 👇

1425 1

Comments