Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
4 views

important methods Functions with javascript

important methods Functions with javascript

Uploaded by

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

important methods Functions with javascript

important methods Functions with javascript

Uploaded by

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

Important Methods and

Built-in functions in JavaScript

@_codevalley
Zuhaib Asif
@_codevalley Zuhaib Asif

String Methods:

const text = "Hello, Code Valley";


console.log(text.length); // 17
console.log(text.toUpperCase()); // "HELLO, CODE
VALLEY"
console.log(text.indexOf("Valley")); // 12
console.log(text.slice(7, 12)); // "Code "
console.log(text.replace("Hello", "Hi")); // "Hi, Code
Valley"
@_codevalley Zuhaib Asif

Array Methods:

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


console.log(numbers.length); // 5
console.log(numbers.join("-")); // "1-2-3-4-5"
console.log(numbers.indexOf(3)); // 2
console.log(numbers.slice(1, 3)); // [2, 3]
console.log(numbers.map(num => num * 2)); // [2, 4, 6,
8, 10]
@_codevalley Zuhaib Asif

Math functions:

console.log(Math.random()) // Random number between


0 and 1
console.log(Math.round(3.7)); // 4
console.log(Math.floor(5.9)); // 5
console.log(Math.max(3, 7, 1, 9)); // 9
console.log(Math.sqrt(16)); // 4
console.log(Math.abs(-5)); // 5 (absolute
value)
console.log(Math.pow(2, 3)); // 8 (2 raised to
the power of 3)
console.log(Math.ceil(2.1)); // 3 (round up)
console.log(Math.min(3, 7, 1, 9)); // 1 (smallest
number among 3, 7, 1, 9)
@_codevalley Zuhaib Asif

Object Methods:

const person = { name: "abc", age: 20 };


const keys = Object.keys(person); // ["name", "age"]
const values = Object.values(person); // ["abc", 20]
const entries = Object.entries(person); // [["name",
"abc"], ["age", 20]]
const hasName = person.hasOwnProperty("name"); // true
@_codevalley Zuhaib Asif

Date Methods:

const currentDate = new Date();


console.log(currentDate.getFullYear()); // Current year
console.log(currentDate.getMonth()); // Current month
(0-11)
console.log(currentDate.getDate()); // Current day of
the month
console.log(currentDate.getHours()); // Current hour
(0-23)
console.log(currentDate.getMinutes()); // Current
minute (0-59)

You might also like