Overview of different type function

What is function?

Functions are the main “building blocks” of the program. They allow the code to be called many times without repetition.

Example:

What is a Default Parameter in a JavaScript function?

A JavaScript function can have default parameters values. Using default function parameters, you can initialize formal parameters with default values. If you do not initialize a parameter with some value, then the default value of the parameter is undefined.

What is Arrow function in javascript?

Arrow functions were introduced with ES6 as a new syntax for writing JavaScript functions. They save developers time and simplify function scope.

Example:

What is anonymous function?

An anonymous function is a function without a name. An anonymous function is often not accessible after its initial creation.

Example:

Rest parameter in javascript

The rest of the parameters can be included in the function definition by using three dots ... followed by the name of the array that will contain them. The dots literally mean gather the remaining parameters into an array.

Spread operator in javascript

The spread operator is a new addition to the set of operators in JavaScript ES6. It takes in an iterable (e.g an array) and expands it into individual elements. The spread operator is commonly used to make shallow copies of JS objects. Using this operator makes the code concise and enhances its readability.

Variable hoisting

Hoisting is a JavaScript mechanism where variables and function declarations are moved to the top of their scope before code execution. Inevitably, this means that no matter where functions and variables are declared, they are moved to the top of their scope regardless of whether their scope is global or local.

Block level function with strict mode and without strict mode

Two type of block level function

1. Works outside the block level function scope without strict mode.

2. Don’t works outside the block level function scope with strict mode. Showed result is undefined.

Block binding in loop

If you assign a variable using var keyword in loop, you can access it from outside.

If you assign a variable using let keyword in loop, you can not access it from outside.

Try Catch in javascript

If there is an error in the code, a try catch is used to handle it.

Coding style

Comment

single line comment: Single-line comments are used to comment a part of a line or a full line of code in JavaScript. Use these symbol //

multi-line comment: JavaScript multiline comment has the same purpose as a single-line comment. JavaScript comment block starts with two symbols: /*. To end the comment, use these symbols */ again. Everything between these symbols will be treated as a comment in JavaScript.

Engineer | Web Developer | Programmer

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store