if statements

Estimated reading: 1 minute 66 views

Sometimes you only want to run a block of code under certain conditions. Flow control — viaifand elseblocks — lets you run code only under certain conditions

				
					var foo = true;
 var bar = false;
 if (bar) {
 // this code will never run
 console.log(’hello!’);
 }
 if (bar) {
 // this code won’t run
 } else {
 if (foo) {
 // this code will run
 } else {
 // this code would run if foo and bar were both false
 }
 }
				
			
Share this Doc

if statements

Or copy link