-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnew.js
More file actions
129 lines (89 loc) · 1.9 KB
/
new.js
File metadata and controls
129 lines (89 loc) · 1.9 KB
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
120
121
122
123
124
125
126
127
128
129
console.log("Hello World");
var x =5;
x=10;
let y=10;
y=11;
console.log(x);
console.log(y);
//--------------------------
//scope
{
var x= 100;
let y= 101;
const z =22;
}
// console.log(y,z); cannot access outside scope
console.log(x)
const value = 143121;
const value2 = 'apple';
console.log(typeof value, typeof value2)
//--------------------------
//string manipulation
const str1 = "I am a String in JavaScript"
console.log(str1.length, str1.endsWith('g'), str1.split(' '))
console.log(str1.lastIndexOf('t'))
//--object
const obj = {
id: 1,
name: 'New Name'
}
console.log(obj)
//
//loops
for (i=0; i<=10; i++){
console.log(i);
}
let arr =[1, 2, 3, 4, ,5]
for (let val of arr){
console.log(val);
}
for (let keys in {name: 'Ram', age: 23}){
console.log(keys)
}
//json
const person = {
id: 1,
name: 'Prashant',
address:{
street: 'Nakhipot',
city: 'Lalitpur'
}
}
const jsonString = JSON.stringify(person);
console.log(jsonString)
const personObj = JSON.parse(jsonString)
console.log(personObj)
//function
function greet(){
console.log('hi')
}
function fx(x,y){
console.log(x+y)
}
greet();
fx(2,4);
function greetPerson(name) {
console.log(`Hello ${name}!`);
}
function greetStranger() {
return 'everyone';
}
greetPerson('John Doe');
greetPerson(greetStranger());
//conditions
flag = true
if (flag){
console.log("hi there")
}
if (flag === true){
console.log("check check")
}
//ternary
console.log(true ? 'true': 'false');
console.log(0 ? 'truth': 'false');
//and or not
console.log(null || 'Default Value');
console.log(undefined || 'Default Value');
console.log('Some Value' && 'Default Value');
console.log(null && 'Default Value');
console.log(undefined && 'Default Value');