"I am Saqib Jahangir. A passionate vlogger, software engineer, trainer and avid traveler with a deep love for exploring the hidden gems of our beautiful planet. With a strong foundation in Application Development, Application Architecture & Database Design and Product Management, I bring over a decade of hands-on experience building secure, scalable, and resilient web applications for a diverse range of industries."


Click Above to BOOK HOTEL NOW!

Built-in Objects and Methods

 

JavaScript comes with several built-in objects that provide ready-to-use properties and methods for common tasks like working with strings, numbers, dates, and more.


1. String Object

Strings represent sequences of characters. The String object provides many helpful methods.

let text = "Hello, JavaScript!";
 
console.log(text.length); // 18
console.log(text.toUpperCase()); // HELLO, JAVASCRIPT!
console.log(text.toLowerCase()); // hello, javascript!
console.log(text.includes("Java")); // true
console.log(text.indexOf("Java")); // 7
console.log(text.slice(7, 17)); // JavaScript

2. Number Object

The Number object provides constants and methods for working with numeric values.

let num = 42.567;
 
console.log(num.toFixed(2)); // "42.57" (round to 2 decimal places)
console.log(Number.isInteger(num)); // false
console.log(Number.parseInt("123px")); // 123
console.log(Number.parseFloat("3.14 meters")); // 3.14

3. Math Object

The Math object contains properties and methods for mathematical calculations.

console.log(Math.PI); // 3.141592653589793
console.log(Math.round(4.7)); // 5
console.log(Math.floor(4.7)); // 4
console.log(Math.ceil(4.1)); // 5
console.log(Math.max(10, 20, 30)); // 30
console.log(Math.random()); // Random number between 0 and 1

4. Date Object

The Date object is used to work with dates and times.

let now = new Date();
 
console.log(now); // Current date and time
console.log(now.getFullYear()); // Year
console.log(now.getMonth() + 1); // Month (0-based, so add 1)
console.log(now.getDate()); // Day of the month
console.log(now.toDateString()); // Human-readable date

5. Array Object (Extra)

Arrays are also built-in objects with powerful methods.

let fruits = ["Apple", "Banana", "Cherry"];
 
console.log(fruits.join(", ")); // "Apple, Banana, Cherry"
console.log(fruits.includes("Banana")); // true
console.log(fruits.reverse()); // ["Cherry", "Banana", "Apple"]
console.log(fruits.sort()); // ["Apple", "Banana", "Cherry"]

 

Click Below to Shop Now at AMAZON

Popular Posts

Operators (Arithmetic, Comparison, Logical)

Functions (Built-in & User-defined)