reading-notes

Functions in JavaScript

Functions are one of the basic building blocks in JavaScript. A work in JavaScript is comparable to a procedure—a set of explanations that performs a assignment or calculates a esteem, but for a method to qualify as a work, it ought to take a few input and return an yield where there’s a few self-evident relationship between the input and the yield. To use a work, you must define it somewhere within the scope from which you would like to call it.

Function declarations

A function definition (also called a function declaration, or function statement) consists of the function keyword, followed by:

The name of the function. A list of parameters to the function, enclosed in parentheses and separated by commas. The JavaScript statements that define the function, enclosed in curly brackets, {…}.

Function expressions

While the function declaration above is syntactically a statement, functions can also be created by a function expression.

Such a function can be anonymous; it does not have to have a name.

Calling functions

Defining a function does not execute it. Defining it names the function and specifies what to do when the function is called.

Calling the function actually performs the specified actions with the indicated parameters.

Function scope

Variables defined inside a function cannot be accessed from anywhere outside the function, because the variable is defined only in the scope of the function. However, a function can access all variables and functions defined inside the scope in which it is defined.

In other words, a function defined in the global scope can access all variables defined in the global scope. A function defined inside another function can also access all variables defined in its parent function, and any other variables to which the parent function has access.

You can read more about functions by visiting Functions in JavaScript

Operators

Types of operators in JavaScript

  1. Assignment operators

  2. Comparison operators

  3. Arithmetic operators

  4. Bitwise operators

  5. Logical operators

  6. String operators

  7. Conditional (ternary) operator

  8. Comma operator

  9. Unary operators

  10. Relational operators

* I’ve already talked about the operators in Read5 to read more about them visit Operators in JavaScript*