forked from AdarshPawar29/JavaScript-Sessions
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsession2.js
119 lines (92 loc) · 2.28 KB
/
session2.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
// Array - variable that hold multipale values
const number = new Array(1, 2, 3, 4, 5, 6);
console.log(number);
const fruits = ['Apple', 'Orange', 30, true, 3.7];
fruits[4] = 'End';
fruits.push('Hello');
fruits.unshift('Banana'); //add element in the 1st position
fruits.pop();
console.log(fruits);
console.log(fruits[1]);
console.log(Array.isArray(fruits)); // to check whether its array or not
console.log(fruits.indexOf('Apple')); //find the possition of the elements
//Object litrals
const person = {
firstName: 'Adarsh',
lastName: 'Pawar',
age: 30,
hobbies: ['Music', 'Movies', 'Sport'],
adrdess: {
street: '211A Bakers street',
city: 'Boston',
state: 'MA'
}
}
person.email = '[email protected]';
console.log(person);
console.log(person.firstName);
console.log(person.hobbies[1]);
//const {firstName, lastName} = person;
//console.log(firstName);
const {
firstName,
lastName,
adrdess: {
city
}
} = person;
console.log(city)
// Array todos
const todos = [{
id: 1,
text: 'Take out trash',
isCompleted: true
},
{
id: 2,
text: 'Meeting with boss',
isCompleted: true
},
{
id: 3,
text: 'Dentist appt',
isCompleted: false
}
];
console.log(todos);
console.log(todos[1].text);
//About JSON
const todosJSON = JSON.stringify(todos); // convert the object litraters into JSON format
console.log(todosJSON);
//funtions
function addNum(num1, num2) {
return num1 + num2;
}
console.log(addNum(2, 3));
//ES6 Function
const addNums = (num1, num2) => {
return num1 + num2;
}
console.log(addNums(2, 3));
//can be writern like that we dont need {}
const multiNums = (num1, num2) => num1 * num2;
console.log(multiNums(2, 3));
let obj = {
myVar: 'foo',
myFunc: function () {
console.log(window.myVar);
}
}
obj.myFunc(); //foo
console.log(obj.myVar); //foo
//Prototypes
Person.prototype.getBirthYear = function () {
return this.dob.getFullYear();
}
// Intantiate object
const person1 = new Person('Adarsh', 'Pawar', '06-08-1996');
const person2 = new Person('Wanda', 'Kaur', '02-01-1994');
console.log(person2);
console.log(person2.dob.getDate);
console.log(person1.getBirthYear());
console.log(person2.getFullName());