Important Methods and
Built-in functions in JavaScript
@_codevalley
Zuhaib Asif
@_codevalley Zuhaib Asif
String Methods:
const text = "Hello, Code Valley";
[Link]([Link]); // 17
[Link]([Link]()); // "HELLO, CODE
VALLEY"
[Link]([Link]("Valley")); // 12
[Link]([Link](7, 12)); // "Code "
[Link]([Link]("Hello", "Hi")); // "Hi, Code
Valley"
@_codevalley Zuhaib Asif
Array Methods:
const numbers = [1, 2, 3, 4, 5];
[Link]([Link]); // 5
[Link]([Link]("-")); // "1-2-3-4-5"
[Link]([Link](3)); // 2
[Link]([Link](1, 3)); // [2, 3]
[Link]([Link](num => num * 2)); // [2, 4, 6,
8, 10]
@_codevalley Zuhaib Asif
Math functions:
[Link]([Link]()) // Random number between
0 and 1
[Link]([Link](3.7)); // 4
[Link]([Link](5.9)); // 5
[Link]([Link](3, 7, 1, 9)); // 9
[Link]([Link](16)); // 4
[Link]([Link](-5)); // 5 (absolute
value)
[Link]([Link](2, 3)); // 8 (2 raised to
the power of 3)
[Link]([Link](2.1)); // 3 (round up)
[Link]([Link](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 = [Link](person); // ["name", "age"]
const values = [Link](person); // ["abc", 20]
const entries = [Link](person); // [["name",
"abc"], ["age", 20]]
const hasName = [Link]("name"); // true
@_codevalley Zuhaib Asif
Date Methods:
const currentDate = new Date();
[Link]([Link]()); // Current year
[Link]([Link]()); // Current month
(0-11)
[Link]([Link]()); // Current day of
the month
[Link]([Link]()); // Current hour
(0-23)
[Link]([Link]()); // Current
minute (0-59)