Created
December 4, 2016 04:03
-
-
Save anonymous/c8b74125d399e98c10e350b5e3d82b47 to your computer and use it in GitHub Desktop.
Control Flow Control flow studies // source https://jsbin.com/xitune
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta name="description" content="Control flow studies"> | |
<meta charset="utf-8"> | |
<meta name="viewport" content="width=device-width"> | |
<title>Control Flow</title> | |
</head> | |
<body> | |
<script id="jsbin-javascript"> | |
// -----Control Flow----- // | |
/* If statements are used in Javascript to make decisions--whether to execute a following | |
code or not. An if statement first evaluates the boolean within parentheses and then executes | |
the code within curly braces if the boolean was true: */ | |
"use strict"; | |
if (typeof "Is this a string?" === "string") { | |
console.log("Yup, it was a string"); | |
} | |
/* If the boolean resolves to false, the code is simply passed over. Further keywords can | |
be used along with the if keyword to create chains of if else statements: */ | |
var arr = []; | |
if (typeof arr === "string") { | |
console.log("I will be skipped :( "); | |
} else if (typeof arr === "number") { | |
console.log("I'm gonna be skipped, too! :((( "); | |
} else if (Array.isArray(arr)) { | |
console.log("Finally!"); | |
} | |
/* lastly, a final else keyword can conclude chain, providing a default result if none of | |
the provided statements resolve to true. */ | |
arr = {}; | |
if (typeof arr === "string") { | |
console.log("I will be skipped :( "); | |
} else if (typeof arr === "number") { | |
console.log("I'm gonna be skipped, too! :((( "); | |
} else if (Array.isArray(arr)) { | |
console.log("Finally!"); | |
} else { | |
console.log("You lied to me! I'll never forgive you."); | |
} | |
</script> | |
<script id="jsbin-source-javascript" type="text/javascript">// -----Control Flow----- // | |
/* If statements are used in Javascript to make decisions--whether to execute a following | |
code or not. An if statement first evaluates the boolean within parentheses and then executes | |
the code within curly braces if the boolean was true: */ | |
if (typeof "Is this a string?" === "string") { | |
console.log("Yup, it was a string"); | |
} | |
/* If the boolean resolves to false, the code is simply passed over. Further keywords can | |
be used along with the if keyword to create chains of if else statements: */ | |
var arr = []; | |
if (typeof arr === "string") { | |
console.log("I will be skipped :( "); | |
} else if (typeof arr === "number") { | |
console.log("I'm gonna be skipped, too! :((( "); | |
} else if (Array.isArray(arr)) { | |
console.log("Finally!"); | |
} | |
/* lastly, a final else keyword can conclude chain, providing a default result if none of | |
the provided statements resolve to true. */ | |
arr = {}; | |
if (typeof arr === "string") { | |
console.log("I will be skipped :( "); | |
} else if (typeof arr === "number") { | |
console.log("I'm gonna be skipped, too! :((( "); | |
} else if (Array.isArray(arr)) { | |
console.log("Finally!"); | |
} else { | |
console.log("You lied to me! I'll never forgive you."); | |
}</script></body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// -----Control Flow----- // | |
/* If statements are used in Javascript to make decisions--whether to execute a following | |
code or not. An if statement first evaluates the boolean within parentheses and then executes | |
the code within curly braces if the boolean was true: */ | |
"use strict"; | |
if (typeof "Is this a string?" === "string") { | |
console.log("Yup, it was a string"); | |
} | |
/* If the boolean resolves to false, the code is simply passed over. Further keywords can | |
be used along with the if keyword to create chains of if else statements: */ | |
var arr = []; | |
if (typeof arr === "string") { | |
console.log("I will be skipped :( "); | |
} else if (typeof arr === "number") { | |
console.log("I'm gonna be skipped, too! :((( "); | |
} else if (Array.isArray(arr)) { | |
console.log("Finally!"); | |
} | |
/* lastly, a final else keyword can conclude chain, providing a default result if none of | |
the provided statements resolve to true. */ | |
arr = {}; | |
if (typeof arr === "string") { | |
console.log("I will be skipped :( "); | |
} else if (typeof arr === "number") { | |
console.log("I'm gonna be skipped, too! :((( "); | |
} else if (Array.isArray(arr)) { | |
console.log("Finally!"); | |
} else { | |
console.log("You lied to me! I'll never forgive you."); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment