DEV Community

Muhammad    Uzair
Muhammad Uzair

Posted on

Basic Concepts of Javascript

This post is based on some basic concepts about JavaScript for Junior Developers and for someone out there looking for an Interview

1) How to copy or clone an array?

In the old way, we can copy an array with slice().
const newaaray= oldarray.slice();
after ES6, we can copy array with the spread operator
Const newarray = [...sheeps]

2) What is the output of +‘16’?

The result is number 16 of type number because the unary operator tries to convert all strings, boolean and null to number.
+‘-5’ gives -5
+’0xFF’ gives output 255
+‘false’ gives 0
+‘Infinity’ gives Infinity
+’infinity’ gives NaN
+’function’ gives NaN

3) What does this return?

!!hello == true
Answer is true

4) Why can’t we use = to copy an array like (new_variable = existing_array) ?

Because an array are reference value in javascript. When we write newarray = oldarray, we don’t create new array rather it's reference that point to the same memory location

5) What is Variable Hoisting in JacaScript?

Hoisting is a JavaScript mechanism where variables and function declarations are moved to the top of their scope before code execution regardless of whether their scope is global or local

6) What Closures ?
Closures is simply the ability of a function at the time of declaration to remember the references of variables and parameters on its current scope, on its parent function scope, on its parent's parent function scope until it reaches the global scope with the help of Scope Chain. Basically it is the Scope created when the function was declared

7) Value of This in JavaScript?
The value of , this refers to the value of the object that is currently executing or invoking the function.
Arrow Functions doesn't have their own this , in this situation it is refers to its parent

8) Arrow Functions
Arrow functions allow us to write shorter function syntax ,Another significant advantage it offers is the fact that it does not bind its own this. In other words, the context inside arrow functions is lexically or statically defined.

Basic Syntax for arrow function

hello = () => {
return "Hello World!";
}

9) Event Bubbling
When an event occurs on a DOM element, that event does not entirely occur on that just one element. In the Bubbling Phase, the event bubbles up or it goes to its parent, to its grandparents, to its grandparent's parent until it reaches all the way to the window.

10) What are Higher Order Functions?

Higher-Order Function are functions that can return a function or receive argument or arguments which has a value of a function.
function higherOrderFunction(param,callback){
return callback(param);
}

Top comments (0)