Skip to content
If statement checks a condition and will execute a task if the condition evaluates to true.if (isMailSent) { console.log(‘Mail sent to recipient’}; 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.if (isTaskCompleted){console.log(‘Task Completed’);} else{console.log(‘Task Incomplete’);} Comparison operators, include <, >, <=, >=, ===, 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 expressions is truthy. The bang operator ! switches the truthiness and falsiness of a value. The ternary operator is shorthand to simplify concise if… else statements.isNightTime ? console.log(‘Lights on!’) : console.log(‘Lights off!’); 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.switch (food){ case ‘oyster’ : console.log(‘Enjoy the taste of the sea’); break ; case ‘pizza’ : console.log (‘Enjoy a delicious pie’); break ; default : console.log(‘Enjoy your meal’);} https://www.codecademy.com/learn/introduction-to-javascript/modules/learn-javascript-control-flow/reference
Variables
Variable hold reusable data in a program and associate it with a name. Variables are stored in memory. ‘var ‘ keyword is used in pre-ES6 versions of JS ‘let ‘ is the preferred way to declare a variable. It can be reassigned. ‘const ‘ is the preferred way to declare a variable with a constant value. Variables that have not been initialized store the primitive data type undefined . Mathematical assignment operators make it easy to calculate a new value and assign it to the same variable. + operator is used to concatenate strings including string values held in variables.In ES6, template literals use backticks ` and ${} to interpolate values into a string. The typeof keyword returns the data type (as a string) of a value.