PROGRAMING with JavaScript

Control Flow

The control flow is the order in which the computer executes statements in a script. Code is run in order from the first line in the file to the last line, unless the computer runs across the structures that change the control flow, such as conditionals and loops. Control flow means that when you read a script, you must not only read from start to finish but also look at program structure and how it affects order of execution.

A typical script in JavaScript includes many control structures, including conditionals loops and functions. Parts of a script may also be set to execute when events occur.


Loop

A loop is a sequence of instructions that is continually repeated until a certain condition is met in computer programming. An example would be the process of getting an item of data and changing it, and then making sure some condition is checked such as, if a counter has reached a prescribed number.


Function

A JavaScript function is a block of code designed to perform a particular task. Functions are one of the fundamental building blocks in JavaScript. A function is similar to a procedure, a set of statements that performs a task or calculates a value, but for a procedure to qualify as a function, it should take some input and return an output where there is some obvious relationship between the input and the output. To use a function, you must define it somewhere in the scope from which you wish to call (invoke) it.

JavaScript Function Syntax

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

Types of Functions

  • Anonymous Function: Is a function without a function name. Only function expressions can be anonymous, function declarations must have a name.

  • Inner Function: Is a function inside another function.

  • Outer Function: Is a function containing a function.

  • Recursive Function: Is a function that calls itself.

  • Immediately Invoked Function Expressions (IIFE): Is a function that is called directly after the function is loaded into the browser’s compiler.


Operators

In JavaScript, an operator is a special symbol used to perform operations on operands or values.


-back