Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 08dc069

Browse filesBrowse files
committed
Improve comments in script.js for clarity on equality and logical operators
1 parent 6afeeb5 commit 08dc069
Copy full SHA for 08dc069

File tree

Expand file treeCollapse file tree

1 file changed

+36
-27
lines changed
Filter options
  • JAVASCRIPT BASICS/Variables In JS/2-Operators & Conditionals
Expand file treeCollapse file tree

1 file changed

+36
-27
lines changed

‎JAVASCRIPT BASICS/Variables In JS/2-Operators & Conditionals/script.js

Copy file name to clipboardExpand all lines: JAVASCRIPT BASICS/Variables In JS/2-Operators & Conditionals/script.js
+36-27Lines changed: 36 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -125,54 +125,63 @@ console.log(typeof num2); //string
125125
let num3 = 5;
126126
console.log(typeof num3); //number
127127

128-
console.log(num2 == num3); //true Loose Equality just check the value
129-
console.log(num2 === num3); //false Strict Equality check the value and type of data both
128+
console.log(num2 == num3); //true because Loose Equality just check the value
130129

131-
// Ternary Operator:
130+
console.log(num2 === num3); //false because Strict Equality check the value and type of data both
132131

133-
//Syntax: condition ? expression1 : expression2
132+
/* Ternary Operator:
133+
134+
Syntax: condition ? expression1 : expression2
134135
135136
let age = 20;
136137
let check = age > 18 ? 'I can vote' : 'I cannot vote';
137-
console.log(check); //I can vote
138+
console.log(check);
138139
140+
Output: I can vote
141+
*/
139142
//__________________________________________________________________________________________
140143

141-
//4. Logical Operators: [&&, ||, !]:
144+
/* 4. Logical Operators: [&&, ||, !]:
145+
146+
1. Logical AND (&&):
147+
148+
=> It returns true if all the conditions are true.
149+
=> If any one of the conditions is false, it returns false.
150+
=> It is denoted by '&&'
151+
=> Syntax: condition1 && condition2
152+
153+
2. Logical OR (||):
142154
143-
//1. Logical AND (&&): It returns true if all the conditions are true.
144-
//If any one of the conditions is false, it returns false.
145-
//It is denoted by '&&'
146-
//Syntax: condition1 && condition2
155+
=> It returns true if any one of the conditions is true.
156+
=> If all the conditions are false, it returns false.
157+
=> It is denoted by '||'
158+
=> Syntax: condition1 || condition2
147159
148-
//2. Logical OR (||): It returns true if any one of the conditions is true.
149-
//If all the conditions are false, it returns false.
150-
//It is denoted by '||'
151-
//Syntax: condition1 || condition2
160+
3. Logical NOT (!):
152161
153-
//3. Logical NOT (!): It returns the opposite of the condition.
154-
//If the condition is true, it returns false.
155-
//If the condition is false, it returns true.
156-
//It is denoted by '!'
157-
//Syntax: !condition
162+
=> It returns the opposite of the condition.
163+
=> If the condition is true, it returns false.
164+
=> If the condition is false, it returns true.
165+
=> It is denoted by '!'
166+
=> Syntax: !condition */
158167

159168
let ans = (true && true && true);
160-
console.log(ans); //true
169+
console.log(ans); //It will return 'true' because all the conditions are true.
161170

162171
let ans1 = (true && true && false);
163-
console.log(ans1); //false
172+
console.log(ans1); //It will return 'false' because one of the conditions is false.
164173

165174
let ans2 = (true || false || false);
166-
console.log(ans2); //true
175+
console.log(ans2); //It will return 'true' because one of the conditions is true.
167176

168177
let ans3 = (false || false || false);
169-
console.log(ans3); //false
178+
console.log(ans3); //It will return 'false' because all the conditions are false.
170179

171180
let ans4 = !(true);
172-
console.log(ans4); //false
181+
console.log(ans4); //false
173182

174183
let ans5 = !(false);
175-
console.log(ans5); //true
184+
console.log(ans5); //true
176185

177186
//AND Operator:
178187

@@ -232,7 +241,7 @@ console.log(!isFirst); //false //It will return false because the value of isFi
232241
//Truthy values: A value is considered truthy if it is not false.
233242
//Falsy values: A value is considered falsy if it is false, [null, undefined, 0, NaN, or an empty string].
234243

235-
console.log(false || 'Balaram'); //Balaram
236-
console.log(false || 7); //7
244+
console.log(false || 'Balaram'); //Balaram
245+
console.log(false || 7); //7
237246
console.log(false || 7 || 8 || 9); //7 //It will return the first truthy value it encounters
238247

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.