An Article On Conditional, Loops (for, Do), Functions Declaration, Fucntion Scope, Nesting Functions And Function Hoisting

An Article On Conditional, Loops (for, Do), Functions Declaration, Fucntion Scope, Nesting Functions And Function Hoisting

AN ARTICLE ON CONDITIONAL, LOOPS (FOR, DO), FUNCTIONS DECLARATION, FUCNTION SCOPE, NESTING FUNCTIONS AND FUNCTION HOISTING

Conditional:

Are used to execute different actions based on different conditions. The most common conditional statement is the if…else statement, which executes a block of code if a specified condition is true, and another block of code if the condition is false. Another way to write conditional statements in JavaScript is by using the ternary operator. The ternary operator is a shorthand way of writing an if…else statement in a single line. It takes three operands: a condition followed by a question mark (?), then an expression to execute if the condition is truth followed by a colon (:), and finally the expression to execute if the condition is false.

Examples of Conditional

In this example, the ternary operator checks if the age is greater than or equal to 21. If it is, the value of beverage is set to "Beer". Otherwise, the value of beverage is set to "Juice"

Loops:

Loops helps in running code repeatedly.

This loop will execute the code block 10 times, with [i] starting at 0 and incrementing by 1 each time until it reaches 9. The code block can be any valid JavaScript code.

Here is an example of a do-while loop in JavaScript:

This loop will execute the code block at least once, and then continue to execute it as long as the condition [i] < 10 is true. The code block can be any valid JavaScript code.

Functions:

A JavaScript function is a block of code that performs a specific task. It is executed when “something” invokes it (calls it) . A function is defined with the function keyword, followed by a name, and then parentheses (). Function names can contain letters, digits, underscores, and dollar signs. The parentheses may include parameter names separated by commas.

Here is an example of a function that computes the product of two numbers:

Functions can be invoked in several ways, including when an event occurs, when it is called from JavaScript code, or automatically (self-invoked) .

Functions can also be used as variable values in all types of formulas, assignments, and calculations .

Also,

A JavaScript function is defined with the function keyword,followed by a name, followed by parentheses ().

The code to be executed, by the function, is placed inside curly brackets: {}

For more further studies, you can visits:

https://www.w3schools.com/js/js_functions.asp

Functions - JavaScript | MDN (mozilla.org)

Functions (javascript.info)

JavaScript 101: Conditionals and Loops | CodeSpot