JavaScript Interview Questions
1 .
If you need to calculate the Fibonacci series in JS, what will you do?
Fibonacci series is a pattern in which each given value is the sum of the previous two, and it starts with 0,1.
 
Method :
 
* use function fib(n),
* Declare var a=0 and b=1
* Use this condition (var i=0; i<n; i++)
* Use var temp = a+b;
* Next make a=b
* And b=temp;
* }
* Return a;

The series will come like 0,1,1,2,3,5…
2 .
In JavaScript, append a new element at the end of the array.
To append an element in a JavaScript array, we use push(), and to remove an array, pop() is used.
 
Syntax :
array.push(item1, item2, …, itemX)
3 .
How do we add/remove properties to objects dynamically in JS?
We can add a property to an object by using :
object.property_name =value
To delete a property, we can use :
object.property_name
Example :
 
   let user = new Object();

    // adding a property

    user.name=’ftl’;

    user.age  =22;

    console.log(user);

    delete user.age;
4 .
What is the procedure to merge two arrays?
Syntax :
 
var arr1 = [1,2,3]
var arr2 = [4,5,6,7]
var mergedArrays = […arr1, …arr2]
document.write(‘Merged arrays’, mergedArrays)
5 .
What is Means by Currying in Javascript?
Currying is a method of evaluating the function with many arguments, into a sequence of function with a single argument. Currying helps you to avoid spending the same variable again and again. It helps to create a larger order function
6 .
How does inheritance work in JavaScript?
When it comes to inheritance, JavaScript simply has one construct: objects. Each object has a separate property which operates a link to another object called its model. That prototype object has a prototype of its individual, and so on until an object is terminated with null as its prototype.
7 .
Why do we use onabort event in JavaScript?
The onabort event is executed when the loading of an image is aborted. Use it in an image tag like this:
 
<img src="demo_image.jpg" onabort="display()">

Here, you can display an alert when the loading of image aborts : 
 
function abortFunc()
{
  alert('Image isn’t loading!');
}
8 .
What are logical errors in JavaScript?
Logic errors occur when there is a mistake in the logic. This can lead your script to work inappropriately to give unexpected results.
9 .
Which event triggers in JavaScript when an object loses focus?
The blur event triggers when object loses focus. An example here displays that we write a name in the textbox and then when the object loses focus, the text color is changed. This happens since the blur event triggers when the focus ends: 
 
<!DOCTYPE html>
<html>
  <body>
  <h2>Testing</h2>
  <input type="text" onblur="display(this)">
    <script>
         function display(z) {
         z.style.color = "green";
       }
    </script>
  </body>
</html> 
10 .
What is the usage of onpagehide event in JavaScript?
When a visitor leaves the web page, then the onpagehide event triggers. The visitor can move to another page or click a link after leaving the current web page. An example here displays an alert box when the user tries to leave the page. This happens since onpagehide event fires when the page is left : 
 
<!DOCTYPE html>
<html>
	<body onpagehide="display()">
	  <p>Close the page</p>
	  <script>
	     function display() {
    	     alert("It was nice having you here!");
	    }
	  </script>
	</body>
</html>