#202124 Darcula theme color
if, else if, and else statements.
**********************************************
comparison operators.
Less than: <
Greater than: >
Less than or equal to: <=
Greater than or equal to: >=
Is equal to: ===
Is NOT equal to: !==
**********************************************
logical operators.
There are three logical operators:
the and operator (&&)
the or operator (||)
the not operator, otherwise known as the bang operator (!)
****************************************************************
truthy vs falsy values.
these values are false values when they are checked as a condition.
0
Empty strings like "" or ''
null which represents when there is no value at all
undefined which represent when a declared variable lacks a value
NaN, or Not a Number
|| it gets the value from left side
&& it gets the vaue from right side.
let tool = 'marker';
// Use short circuit evaluation to assign writingUtensil variable below:
let writingUtensil =tool || "pen";
console.log(`The ${writingUtensil} is mightier than the sword.`);
**********************************************
***ternary operators.***
Normal if else
let isLocked = false;
if (isLocked) {
console.log('You will need a key to open the door.');
} else {
console.log('You will not need a key to open the door.');
}
***ternary if else****
let isLocked = false;
isLocked ?
console.log('You will need a key to open the door.'):
console.log('You will not need a key to open the door.');
**********************************************
the switch statement.
this is an alternative of if-else statement.
because suppose if you want to check 100 of condition then it will be a pain to write that amount of conditions.
that's why we use SWITH CASE.
EXAMPLE :
let athleteFinalPosition = 'third place';
switch(athleteFinalPosition){
case "first place":
console.log('lo');
break;
case "third place":
console.log('third place prints');
break;
case "second place":
console.log('second place prints');
break;
default:
console.log("you loose");
}
if you wil not use break; keyword all the code blocks will run.
you should add break keyoword at the end of the default case
**********************************************
CONDITIONAL STATEMENTS
Review
Way to go! Here are some of the major concepts for conditionals:
An if statement checks a condition and will execute a task if that condition evaluates to true.
if...else statements make binary decisions and execute different code blocks based on a provided condition.
We can add more conditions using else if statements.
Comparison operators, including <, >, <=, >=, ===, and !== can compare two values.
The logical and operator, &&, or “and”, checks if both provided expressions are truthy.
The logical operator ||, or “or”, checks if either provided expression is truthy.
The bang operator, !, switches the truthiness and falseness of a value.
The ternary operator is shorthand to simplify concise if...else statements.
A switch statement can be used to simplify the process of writing multiple else if statements. The break keyword stops the remaining cases from being checked and executed in a switch statement.
you can reffer this for in depth knowladge
if, else if, and else statements.
**********************************************
comparison operators.
Less than: <
Greater than: >
Less than or equal to: <=
Greater than or equal to: >=
Is equal to: ===
Is NOT equal to: !==
**********************************************
logical operators.
There are three logical operators:
the and operator (&&)
the or operator (||)
the not operator, otherwise known as the bang operator (!)
****************************************************************
truthy vs falsy values.
these values are false values when they are checked as a condition.
0
Empty strings like "" or ''
null which represents when there is no value at all
undefined which represent when a declared variable lacks a value
NaN, or Not a Number
|| it gets the value from left side
&& it gets the vaue from right side.
let tool = 'marker';
// Use short circuit evaluation to assign writingUtensil variable below:
let writingUtensil =tool || "pen";
console.log(`The ${writingUtensil} is mightier than the sword.`);
**********************************************
***ternary operators.***
Normal if else
let isLocked = false;
if (isLocked) {
console.log('You will need a key to open the door.');
} else {
console.log('You will not need a key to open the door.');
}
***ternary if else****
let isLocked = false;
isLocked ?
console.log('You will need a key to open the door.'):
console.log('You will not need a key to open the door.');
**********************************************
the switch statement.
this is an alternative of if-else statement.
because suppose if you want to check 100 of condition then it will be a pain to write that amount of conditions.
that's why we use SWITH CASE.
EXAMPLE :
let athleteFinalPosition = 'third place';
switch(athleteFinalPosition){
case "first place":
console.log('lo');
break;
case "third place":
console.log('third place prints');
break;
case "second place":
console.log('second place prints');
break;
default:
console.log("you loose");
}
if you wil not use break; keyword all the code blocks will run.
you should add break keyoword at the end of the default case
**********************************************
CONDITIONAL STATEMENTS
Review
Way to go! Here are some of the major concepts for conditionals:
An if statement checks a condition and will execute a task if that condition evaluates to true.
if...else statements make binary decisions and execute different code blocks based on a provided condition.
We can add more conditions using else if statements.
Comparison operators, including <, >, <=, >=, ===, and !== can compare two values.
The logical and operator, &&, or “and”, checks if both provided expressions are truthy.
The logical operator ||, or “or”, checks if either provided expression is truthy.
The bang operator, !, switches the truthiness and falseness of a value.
The ternary operator is shorthand to simplify concise if...else statements.
A switch statement can be used to simplify the process of writing multiple else if statements. The break keyword stops the remaining cases from being checked and executed in a switch statement.
you can reffer this for in depth knowladge
0 comments:
Post a Comment