Some important topic from JavaScript Block binding and JavaScript function.

Fahad Ezahar
3 min readNov 3, 2020

--

JavaScript Declarations are Hoisted:

If we assign the value first and then declare it, that is basically hoisting. Since hosting is the default behavior, all the functions in JavaScript are hosted in the creation phase. That’s why we can actually call a function before declaring it if we want.

Example :

Block-Level Declarations:

Block-level declarations are those that declare variables that are inaccessible outside of a given block scope.

These block-level scopes can be created either inside of a function, or inside of any code block, such as with an if-else statement or for loop.

Block Binding in Loops:

For this we have to use let not var, cause var is being hoisted. Follow the two examples below:

Functions with Default Parameter Values:

When declaring a function in JavaScript, the parameters that we give are undefined if we do not pass any value in the argument.

If you do not pass the value in the Arguments using the Default Parameters, you can give another value instead of undefined.

The Spread Operator:

The spread operator basically spreads the array and the object.

For example : we have an array of numbers.

const number = [1, 2, 3];

Now what do I do if I want to make a copy of this Array? This means that the data of the previous Array will be there and 4, 5, 6 will be added. Then we can write as follows –

const newNumbers = […number, 4,5,6];

When we spread it out, it will basically copy the number and move on to the new numbers and add 4,5,6.

console.log(newNumbers);

//expected output (1, 2, 3, 4, 5,6);

Arrow Functions:

The simplest way to define an arrow function is to summarize the regular function that we write in JavaScript. This allows us to shorten the syntax of the function.

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

--

--

Fahad Ezahar
Fahad Ezahar

Written by Fahad Ezahar

0 Followers

I continue my learning on the challenges of becoming a professional web developer.

No responses yet

Write a response