Skip to content

Commit 3b1462c

Browse files
Built-In Methods
1 parent 473ac64 commit 3b1462c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+347
-8
lines changed

10. Function-Methods/1. apply().js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// function.apply
2+
3+
const obj = {
4+
name: "Suhail",
5+
age: 20,
6+
call() {
7+
return `Name is ${this.name} and age is ${this.age}`;
8+
},
9+
};
10+
11+
const obj2 = {
12+
name: "Roushan",
13+
age: 22,
14+
};
15+
16+
let data = obj.call.apply(obj2)
17+
console.log(data);
18+

10. Function-Methods/2. bind().js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
const first = {
2+
name: "Suhail",
3+
age: 20,
4+
call() {
5+
return `${this.name} and ${this.age}`;
6+
},
7+
};
8+
9+
const second = {
10+
name: "Suhail",
11+
age: 20,
12+
};
13+
14+
let data = first.call.bind(second);
15+
console.log(data());

10. Function-Methods/3. call().js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
const call = () => `Hello I am Suhail`;
2+
3+
let data = call.call();
4+
console.log(data);

10. Function-Methods/4. name().js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
function name() {
2+
console.log("I am Function Name ");
3+
}
4+
5+
let data = name.name;
6+
console.log(data);

10. Function-Methods/5. length.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
function number(a, b, c) {
2+
console.log(a, b, c);
3+
}
4+
5+
let data = number.length;
6+
7+
console.log(data); // 3
8+
9+
function odd(a, b = 10, c) {
10+
console.log(a, b, c);
11+
}
12+
13+
data = odd.length;
14+
15+
console.log(data); // 1
16+
17+
/*
18+
a=11,b,c ===> 0
19+
a,b=11,c ===> 1
20+
a,b,c=10 ===> 2
21+
22+
// It always count from first
23+
24+
*/

10. Function-Methods/6. toString().js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
function Suhail() {
2+
return "Hey Everyone";
3+
}
4+
5+
console.log(Suhail.toString());
6+
7+
8+
9+
// Output:-
10+
// function Suhail() {
11+
// return "Hey Everyone";
12+
// }

11. Number-Methods/1. isFinite().js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
let number = 775;
2+
console.log(isFinite(number)); // true
3+
4+
let number2 = "745533e3";
5+
console.log(isFinite(number2)); // true
6+
7+
let number3 = 745533e3;
8+
console.log(isFinite(number3)); // true
9+
console.log(isFinite(null)); // true
10+
11+
console.log(isFinite(NaN)); // false
12+
console.log(isFinite(-Infinity)); // false
13+
console.log(isFinite(+Infinity)); // false
14+
console.log(isFinite(undefined)); // false

11. Number-Methods/2. isInteger().js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
console.log(Number.isInteger(123)); // true
2+
console.log(Number.isInteger(3473.345)); // false
3+
console.log(Number.isInteger("873")); // false
4+
console.log(Number.isInteger(1e1)); // true
5+
6+
console.log(Number.isInteger(5.0)); // true; 5.0 == 5
7+
console.log(Number.isInteger(0.5)); // false 0.5
8+

11. Number-Methods/3. parseFloat().js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// String to Number
2+
3+
let data = "123";
4+
let change = Number.parseFloat(data);
5+
console.log(typeof change,change);
6+
7+
let data2 = "123e4";
8+
change = Number.parseFloat(data2);
9+
console.log(typeof change, change);
10+
11+
12+
let data3 = "d234eNde";
13+
change = Number.parseFloat(data3);
14+
console.log(typeof change, change);
15+
16+
17+
let data4 = "234eNde";
18+
change = Number.parseFloat(data4);
19+
console.log(typeof change, change);

11. Number-Methods/4. parseInt().js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
let number = 0000;
2+
console.log(parseInt(number,2));
3+
4+
5+
number = 0001;
6+
console.log(parseInt(number,2));
7+
8+
number = " 0xF"
9+
console.log(parseInt(number, 16));
File renamed without changes.
File renamed without changes.

11. Number-Methods/Other.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
console.log(Number.MIN_SAFE_INTEGER);
2+
3+
console.log(Number.MAX_SAFE_INTEGER);
4+
console.log(Number.MIN_VALUE);
5+
console.log(Number.MAX_VALUE);
6+
7+
console.log(Number.EPSILON); // 2.220446049250313e-16
8+
9+
console.log(Number.NEGATIVE_INFINITY);
10+
console.log(Number.POSITIVE_INFINITY);
11+
console.log(Number.NaN);
12+
13+
/*
14+
15+
-9007199254740991
16+
9007199254740991
17+
5e-324
18+
1.7976931348623157e+308
19+
2.220446049250313e-16
20+
-Infinity
21+
Infinity
22+
NaN
23+
24+
*/

6. Types in JavaScript/40.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// for in Loop
2+
// Use for Objects only ...Dont Use In Arrays (if index is matter for you)
3+
4+
let data = {
5+
name: "Suhail",
6+
age: 20,
7+
isAlive: true,
8+
favnum: [10, 20, 11],
9+
address: {
10+
city: "Hyderabad",
11+
},
12+
};
13+
14+
for (let i in data) {
15+
console.log(`Key is this ${i} : ${data[i]} Value`);
16+
}

6. Types in JavaScript/54.js

Whitespace-only changes.

6. Types in JavaScript/55.js

Whitespace-only changes.

6. Types in JavaScript/56.js

Whitespace-only changes.

6. Types in JavaScript/57.js

Whitespace-only changes.

6. Types in JavaScript/58.js

Whitespace-only changes.

6. Types in JavaScript/59.js

Whitespace-only changes.

6. Types in JavaScript/60.js

Whitespace-only changes.

6. Types in JavaScript/61.js

Whitespace-only changes.

6. Types in JavaScript/62.js

Whitespace-only changes.

6. Types in JavaScript/63.js

Whitespace-only changes.

6. Types in JavaScript/64.js

Whitespace-only changes.

6. Types in JavaScript/65.js

Whitespace-only changes.

6. Types in JavaScript/66.js

Whitespace-only changes.

6. Types in JavaScript/67.js

Whitespace-only changes.

6. Types in JavaScript/68.js

Whitespace-only changes.

6. Types in JavaScript/69.js

Whitespace-only changes.

6. Types in JavaScript/70.js

Whitespace-only changes.

6. Types in JavaScript/71.js

Whitespace-only changes.

6. Types in JavaScript/72.js

Whitespace-only changes.

6. Types in JavaScript/73.js

Whitespace-only changes.

6. Types in JavaScript/74.js

Whitespace-only changes.

6. Types in JavaScript/75.js

Whitespace-only changes.

6. Types in JavaScript/76.js

Whitespace-only changes.

6. Types in JavaScript/77.js

Whitespace-only changes.

6. Types in JavaScript/78.js

Whitespace-only changes.

6. Types in JavaScript/79.js

Whitespace-only changes.

6. Types in JavaScript/80.js

Whitespace-only changes.

6. Types in JavaScript/81.js

Whitespace-only changes.

6. Types in JavaScript/82.js

Whitespace-only changes.

6. Types in JavaScript/83.js

Whitespace-only changes.

6. Types in JavaScript/84.js

Whitespace-only changes.

6. Types in JavaScript/85.js

Whitespace-only changes.

6. Types in JavaScript/86.js

Whitespace-only changes.

6. Types in JavaScript/87.js

Whitespace-only changes.

6. Types in JavaScript/88.js

Whitespace-only changes.

6. Types in JavaScript/89.js

Whitespace-only changes.

6. Types in JavaScript/90.js

Whitespace-only changes.

9. Object-Methods/Important.txt

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
Link : https://blog.devgenius.io/ultimate-js-object-methods-cheatsheet-2022-5adc88cdc074
2+
3+
4+
Managing Objects
5+
// Create object with an existing object as prototype
6+
Object.create()
7+
8+
// Adding or changing an object property
9+
Object.defineProperty(object, property, descriptor)
10+
11+
// Adding or changing object properties
12+
Object.defineProperties(object, descriptors)
13+
14+
// Accessing Properties
15+
Object.getOwnPropertyDescriptor(object, property)
16+
17+
// Returns all properties as an array
18+
Object.getOwnPropertyNames(object)
19+
20+
// Accessing the prototype
21+
Object.getPrototypeOf(object)
22+
23+
// Returns enumerable properties as an array
24+
Object.keys(object)
25+
26+
Protecting Objects
27+
// Prevents adding properties to an object
28+
Object.preventExtensions(object)
29+
30+
// Returns true if properties can be added to an object
31+
Object.isExtensible(object)
32+
33+
// Prevents changes of object properties (not values)
34+
Object.seal(object)
35+
36+
// Returns true if object is sealed
37+
Object.isSealed(object)
38+
39+
// Prevents any changes to an object
40+
Object.freeze(object)
41+
42+
// Returns true if object is frozen
43+
Object.isFrozen(object)
44+
45+
46+
//The method Object.values() allows you to get all the values inside an
47+
object as an array. You just have to pass the object as an argument to
48+
the method Object.values() .
49+
Object.values(object)
50+
51+
52+
// The method Object.entries() is also useful.
53+
It allows you to get both the keys and values
54+
of an object and it returns a multidimensional
55+
array that contains other arrays for each key and value.
56+
Object entries

Pratice/10.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
function Tariq(date, month, year) {
2-
this.date = new Date().getDate()
3-
this.month = new Date().getMonth() + 1
4-
this.year = new Date().getFullYear()
1+
class Tariq {
2+
constructor(date, month, year) {
3+
this.date = new Date().getDate();
4+
this.month = new Date().getMonth() + 1;
5+
this.year = new Date().getFullYear();
6+
}
57
}
68

7-
const tariq = new Tariq()
9+
const tariq = new Tariq();
810
console.log(tariq);
911

10-
console.log(tariq.date);
12+
console.log(tariq.date, tariq.month);
1113
console.log(tariq.month);
1214
console.log(tariq.year);
13-
14-

Pratice/19.js

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
// let a1 = {
2+
// name: "Suhail",
3+
// age: 20,
4+
// };
5+
// let a2 = Object.assign(a1);
6+
// console.log(a2);
7+
// a2.isAlive = true;
8+
9+
// console.log(a2);
10+
// console.log(a1);
11+
12+
// let student = {
13+
// name: "suhail",
14+
// age: 20,
15+
// };
16+
17+
// // delete student.age
18+
// console.log(student);
19+
20+
// let obj = Object.create({
21+
// name: "suhail",
22+
// age: 20,
23+
// });
24+
25+
// console.log(obj); // empty
26+
// console.log(obj.name,obj.age); // suhail
27+
28+
// obj.isAlive = true;
29+
// console.log(obj);
30+
// console.log(obj.name,obj.age);
31+
32+
// let a1 = {
33+
// name: "Suhail",
34+
// age: 22,
35+
// address: {
36+
// city: "Hyd",
37+
// },
38+
// };
39+
40+
// Object.freeze(a1);
41+
42+
// console.log(a1);
43+
// a1.isAlive = true // Add
44+
// a1.name = "Roushan" // Update
45+
// a1.address.city= "mumbai"
46+
// delete a1.address // delete
47+
48+
// console.log(a1);
49+
50+
// console.log(Object.isFrozen(a1));
51+
52+
// let a1 = {
53+
// name: "Suhail",
54+
// age: 22,
55+
// address: {
56+
// city: "Hyd",
57+
// },
58+
// };
59+
60+
// Object.seal(a1);
61+
// console.log(Object.isSealed(a1));
62+
63+
// console.log(a1);
64+
65+
// // a1.address.city = true;
66+
// a1.name = "Roushan"
67+
// //
68+
// // a1.isAlive = true;
69+
70+
// delete a1.address
71+
72+
// console.log(a1);
73+
74+
let a1 = {
75+
name: "Suhail",
76+
age: 22,
77+
address: {
78+
city: "Hyd",
79+
},
80+
};
81+
82+
console.log(a1);
83+
84+
85+
Object.preventExtensions(a1)
86+
console.log(a1);
87+
console.log(Object.isExtensible(a1));
88+
89+
90+
console.log(a1);
91+
92+
a1.name = "Roushan"
93+
a1.address.city = "Mumbai"
94+
a1.address.area = "local"
95+
// delete a1.address
96+
97+
98+
console.log(a1);

Pratice/20.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
const a1 = {
2+
name: "Suhail",
3+
age: 20,
4+
};
5+
6+
const { name: fullname, age: saal } = { ...a1 };
7+
8+
const a2 = Object.assign(
9+
{},
10+
{
11+
fullname,
12+
saal,
13+
}
14+
);
15+
16+
console.log(a2);

0 commit comments

Comments
 (0)