Advanced JavaScript Interview Questions



Advanced JavaScript Interview Questions


Advanced JavaScript Interview Questions

10 Read + Advanced JavaScript Interview Questions 2018











Q1. Explain Event bubbling and Event Capturing in JavaScript?

Event Capture and Bubbling: In HTML DOM API there are two ways of event propagation and determines the order in which event will be received. The two ways are Event Bubbling and Event Capturing. The first method event bubbling directs the event to its intended target, and the second is called event capture in which the event goes down to the element.

Event Capture

The capture procedure is rarely used but when it’s used it proves to be very helpful. This process is also called ‘trickling’. In this process, the event is captured first by the outermost element and then propagated to the innermost element. For example:

<div>

<ul>

<li></li>

</ul>

</div>

From the above example, suppose the click event did occur in the ‘li’ element, in that case capturing event it will be first handled ‘div’, then ‘ul’ and at last the target element will be hit that is ‘li’

Event Bubbling

Bubbling just works like the bubbles, the event gets handled by the innermost element and then propagated to the outer element.

<div>
 <ul>

<li></li>

</ul>

</div>

From the above example, suppose the click event did occur in the ‘li’ element in bubbling model the event will be handled first by ‘li’ then by ‘ul’ and at last by ‘div’ element.

2. What close() does in Javascript?

In Javascript close() method is used to close the current window. You must write window.close() to ensure that this command is associated with a window object and not some other JavaScript object.

3.What is the difference between let and var?

There are several differences between let and var. let gives you the privilege to declare variables that are limited in scope to the block; statement of expression, unlike varvar is rather a keyword, which defines a variable globally regardless of block scope.
Global window object:
Even if the let variable is defined as same as var variable globally, the let variable will not be added to the global window object. The similarities are alike when both are used outside the function block.
Blocklet variables are usually used when there is a limited use of those variables. Say, in for loops, while loops or inside the scope of if conditions etc. Basically, where ever the scope of the variable has to be limited.
Redeclaration: let variables cannot be re-declared while var variable can be re-declared in the same scope.
Function: let and var variables work the same way when used in a function block.

4. Explain Closures in JavaScript?

Closures are the combination of lexical environment and function within which the function was declared. This allows JavaScript programmers to write better, more creative, concise and expressive codes. The closure will consist of all the local variables that were in-scope when the closure was created.
Sure, closures appear to be complex and beyond the scope, but after you read this article, closures will be much more easy to understand and more simple for your everyday JavaScript programming tasks. JavaScript is  a very function-oriented language it gives the user freedom to use functions as the wish of the programmer.

5. Explain JavaScript Event Delegation Model?

 In JavaScript, there is some cool stuff that makes it the best of all. One of them is Delegation Model. When capturing and bubbling, allow functions to implement one single handler to many elements at one particular time then that is called event delegation. Event delegation allows you to add event listeners to one parent instead of specified nodes. That particular listener analyzes bubbled events to find a match on the child elements. Many people think it to be complicated but in reality, it is very simple if one starts understanding it.

6. Describe negative infinity in JavaScript?

NEGATIVE_INFINITY property represents negative infinity and is a number in javascript, which is derived by ‘dividing negative number by zero’. It can be better understood as a number that is lower than any other number. Its properties are as follows:
– A number of objects need not to be created to access this static property.
– The value of negative infinity is the same as the negative value of the infinity property of the global object.
The values behave differently than the mathematical infinity:
1. Any positive value, including POSITIVE_INFINITY, multiplied by NEGATIVE_INFINITY is NEGATIVE_INFINITY.
2. Any negative value, including NEGATIVE_INFINITY, multiplied by NEGATIVE_INFINITY is POSITIVE_INFINITY.
3. Zero multiplied by NEGATIVE_INFINITY is NaN.
4. NaN multiplied by NEGATIVE_INFINITY is NaN.
5. NEGATIVE_INFINITY, divided by any negative value except NEGATIVE_INFINITY, is POSITIVE_INFINITY.
6. NEGATIVE_INFINITY, divided by any positive value except POSITIVE_INFINITY, is NEGATIVE_INFINITY.
7. NEGATIVE_INFINITY, divided by either NEGATIVE_INFINITY or POSITIVE_INFINITY, is NaN.
8. Any number divided by NEGATIVE_INFINITY is zero.

7. Explain function hoisting in JavaScript?

JavaScript’s default behavior that allows moving declarations to the top is called Hoisting. The 2 ways of creating functions in JavaScript are Function Declaration and Function Expression. Let’s find out more about these:

Function Declaration

A function with the specific parameters is known as function declarations. To create a variable in JavaScript is called declarations.
e.g:
hoisted(); // logs "foo"

function hoisted() {

  console.log('foo');

}
Function Expression
When a function is created by using an expression it is called function expression.
e.g:
notHoisted(); // TypeError: notHoisted is not a function

var notHoisted = function() {

   console.log('bar');

};
Advanced JavaScript Interview Questions Advanced JavaScript Interview Questions Reviewed by Pakainfo on July 21, 2018 Rating: 5

No comments:

'Heartbroken' family of Nigerian man who died at Calgary airport wants answers

'Heartbroken' family of Nigerian man who died at Calgary airport wants answers Bolante Idowu Alo died following altercation wit...

Powered by Blogger.