JavaScript is a multi-paradigm, dynamic language with types and operators, standard built-in objects, and methods. Its syntax is based on the Java and C languages — many structures from those languages apply to JavaScript as well. JavaScript supports object-oriented programming with object prototypes, instead of classes. JavaScript also supports functional programming — functions are objects, giving functions the capacity to hold executable code and be passed around like any other object.
In Javascript, a control structure, as the term implies, refers to the flow of execution of the program. There are two possible control structures: linear and nonlinear. The linear execution (also called sequential execution) refers to the execution of the statements in the order they are listed. In comparison, the non-linear execution refers to the execution of statements regardless of the order they are listed.
Functions in Javascript
A function is a parametric block of code defined one time and called any number of times later. A function is created with an expression that starts with the keyword ‘function’. The function body of a function created this way must always be wrapped in braces, even when it consists of only a single statement
var hello = function() {
console.log("World!");
};
hello();
//> "World"
function power(base, exponent) {
var result = 1;
for (var count = 0; count < exponent; count++) {
result *= base;
}
return result;
};
console.log(power(2, 10));
//> 1024