You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
letx=10;x+=5;// Equivalent to x = x + 5x-=5;// Equivalent to x = x - 5x*=5;// Equivalent to x = x * 5x/=5;// Equivalent to x = x / 5x%=5;// Equivalent to x = x % 5x**=5;// Equivalent to x = x ** 5
Comparison Operators
leta=10;letb=5;a==b;// Equal toa===b;// Strict equal toa!=b;// Not equal toa!==b;// Strict not equal toa>b;// Greater thana>=b;// Greater than or equal toa<b;// Less thana<=b;// Less than or equal to
Logical Operators
leta=true;letb=false;a&&b;// Logical ANDa||b;// Logical OR!a;// Logical NOT
Conditionals
if Statement
if(condition){// code to be executed if condition is true}
if...else Statement
if(condition){// code to be executed if condition is true}else{// code to be executed if condition is false}
else if Statement
if(condition1){// code to be executed if condition1 is true}elseif(condition2){// code to be executed if condition2 is true}else{// code to be executed if both condition1 and condition2 are false}
switch Statement
switch(expression){casevalue1:
// code to be executed if expression equals value1break;casevalue2:
// code to be executed if expression equals value2break;default:
// code to be executed if expression doesn't match any case}
Loops
for Loop
for(leti=0;i<5;i++){// code to be executed}
while Loop
leti=0;while(i<5){// code to be executedi++;}
do...while Loop
leti=0;do{// code to be executedi++;}while(i<5);
for...in Loop
letobj={a: 1,b: 2,c: 3};for(letkeyinobj){// code to be executed}
for...of Loop
letarr=[1,2,3];for(letvalueofarr){// code to be executed}
classPerson{constructor(name,age){this.name=name;this.age=age;}greet(){console.log(`Hello, my name is ${this.name}`);}}letjohn=newPerson('John',30);john.greet();