JavaScript: Demonstration of basic concepts


Variables

Global Variables:
Local Variable in function:
Nested Funcions

Functions

Function to print username:
printUsername("kMuldoon@nisum.com")


Self invoking anonymous function sqaure a number:
((n) => document.write(n * n))(10);

Conditionals

IF ELSE-IF ELSE

let name = "kyle";
if (name === "bob") { document.write("bob was here"); } else if (name === "joe") { document.write("joe was here"); } else { document.write("Kyle was here"); }

SWITCH

let course = "art"; switch (course) { case "art": document.write("draw like picasso"); break; case "math": document.write("solve like newton"); break; default: document.write("do something else"); }

Loops