function myFunction(p1, p2) { return p1 * p2; // The function returns the product of p1 and p2 }
function name(parameter1, parameter2, parameter3) { // code to be executed }
var x = myFunction(4, 3); // Function is called, return value will end up in x function myFunction(a, b) { return a * b; // Function returns the product of a and b }
function toCelsius(fahrenheit) { return (5/9) * (fahrenheit-32); } document.getElementById("demo").innerHTML = toCelsius(77);
if (condition) { block of code to be executed if the condition is true }
if (hour < 18) { greeting = "Good day"; }
if (condition) { block of code to be executed if the condition is true } } else { block of code to be executed if the condition is false }
if (hour < 18) { greeting = "Good day"; } else { greeting = "Good evening"; }
if (condition1) { block of code to be executed if condition1 is true } else if (condition2) { block of code to be executed if condition1 is false and condition2 is true } else { block of code to be executed if condition1 is false and condition2 is false }
if (hour < 10) { greeting = "Good morning"; } else if (hour < 20) { greeting = "Good day"; } else { greeting = "Good evening"; }
switch(expression) { case n: code block break; case n: code block break; default: default code block }
switch (new Date().getDay()) { case 0: day = "Sunday"; break; case 1: day = "Monday"; break; case 2: day = "Tuesday"; break; case 3: day = "Wednesday"; break; case 4: day = "Thursday"; break; case 5: day = "Friday"; break; case 6: day = "Saturday"; }
switch (new Date().getDay()) { case 1: case 2: case 3: default: text = "Looking forward to the Weekend"; break; case 4: case 5: text = "Soon it is Weekend"; break; case 0: case 6: text = "It is Weekend"; }
* Examples and content from W3Schools.com.