10 Advance thing you should know as a js Developer
By: Mainul Islam Faruqi
Tags: Javascript Tips, Hoisting, JavaScript, Js Block Bindings

1.Hoisting: Hoisting suggests that variable and function declaration are moved to the top of your code before execution.

The above code snippet is we call the function before we write the function and the code still works.

only declarations of the variable are hoisted, not initialization.

Here just initialized the variable not declared and throws ReferenceError exeption

2. Default function parameters: When we declare the function, then we can provide the initial value of parameters. It is also a named parameter.

If we pass the value of named parameters, the value of the default parameters will change.

3. Block-level Declaration: The block is delimited by a pair of curly brackets. Only variable declaration with var can be updated in the block and outside of the block. And let declaration can not be updated in the block but can be updated outside of the block.

4. Block-level function: In strict mode, function in the block are now scooped. That means we can not access the block level function outside the block.

We can't access the block level function outside the block.

5.Spread Operator: Spread operator (…) expanded or copy arguments, (for function calls) elements, (for array literals) key-value pair (for object literals). And put it in a place where use it.

Spread operator copy or expanded elements from the languages array and put it in a place.

Thus, we can expand elements for Array, arg for Function calls, and key value-pair for object.

6. Rest parameters: When declaring a function, we can use rest parameter with the prefix (…) as a last parameter. That means all the remaining arguments to be placed within an array. when we call the function and pass the arguments that are no declared as a parameter. These parameters will pass in the rest parameters.

we declared a, b and …manyMoreArgs (rest parameters). That means when we call the function and pass more than two parameters, then all remaining parameters will pass with rest parameters and returns an Array.

7. Arrow Function:

8. Types of Values: After almost 25 years of studying JavaScript, the scientists have only discovered nine types of value.

Undefined: used for unintentionally missing values. Null: used for intentionally missing values. Booleans(true or false): used for logical operations. Numbers: used for math calculation. Strings: used for text. symbols(uncommon): used for implementation details. BigInts(uncommon and new): used for math on Big numbers. Objects({} and others): used to group related data and code. Functions: Used to refer to code.

9. comments: comments are very important to describe how and why the code works

// used for single line comments.

/* …….. */ used for multiline comments.

10. Coding Style:

curly Braces:

always when starting curly braces, then close the braces to the next line.

2. line length: No one likes to read a long horizontal line of code. So it’s best practice to split them.

3. Indents: Horizontal indents 2 or 4 spaces and vertical indents empty lines for splitting code into logical blocks.

4. Semicolons: A semicolon should be present after each statement.

5. Nesting Levels: Try to avoid nesting code too many levels deep.