JeffLearnsReact – Flow

FLOW Controlling the flow of the execution with if, else if, else, and switch. NOTE: Lines of code between curly braces are called blocks. IF ELSE ELSE IF if/else statements are how programs can process yes/no questions programmatically. SWITCH let groceryItem = ‘papaya’; switch (groceryItem) { case ‘tomato’: console.log(‘Tomatoes are $0.49’); break; case ‘lime’: console.log(‘Limes […]

FLOW

Controlling the flow of the execution with if, else if, else, and switch.

NOTE: Lines of code between curly braces are called blocks.

IF ELSE ELSE IF
if/else statements are how programs can process yes/no questions programmatically.

SWITCH
let groceryItem = ‘papaya’;

switch (groceryItem) {
case ‘tomato’:
console.log(‘Tomatoes are $0.49’);
break;
case ‘lime’:
console.log(‘Limes are $1.49’);
break;
case ‘papaya’:
console.log(‘Papayas are $1.29’);
break;
default:
console.log(‘Invalid item’);
break;
}

Ternary Operator

let isNightTime = true;

if (isNightTime) {
console.log(‘Turn on the lights!’);
} else {
console.log(‘Turn off the lights!’);
}

can also be

isNightTime ? console.log(‘Turn on the lights!’) : console.log(‘Turn off the lights!’);

conditionIsMet ? do-if-true : do-if-false;

Powered by WPeMatico