JavaScript Interview Questions
1 .
What are the common Errors in JavaScript ?
The common errors in JavaScript programming are the following : 

Spelling and typing errors.
Missing brackets or quotation marks.
Mismatching quotation marks.
Using single equal sign instead of double equal sign in comparison.
Referencing objects that does not exist.
Using reserved keywords for the variable naming.
Using the wrong type of brackets.
These are the main causes of these errors.

In JavaScript, there are the following three types of errors :

Syntax Error
Runtime Error
Logic Error
2 .
What Is EncodeURI() Function ?
The encodeURI() function is used to encode a URI. This function encodes all special characters, except these < , / ? : @ & = + $ #>.

Example : 
var uri=" is a educational website";
var encodedURI = encodeURI(uri);

Output :
3 .
What is NaN property in JavaScript?
NaN property represents “Not-a-Number” value. It indicates a value which is not a legal number.
typeof of a NaN will return a Number .
To check if a value is NaN, we use the isNaN() function,

Note :  isNaN() function converts the given value to a Number type, and then equates to NaN.

isNaN("Hello")  // Returns true
isNaN(345)   // Returns false
isNaN('1')  // Returns false, since '1' is converted to Number type which results in 0 ( a number) 
isNaN(true) // Returns false, since true converted to Number type results in 1 ( a number)
isNaN(false) // Returns false
isNaN(undefined) // Returns true
4 .
Explain Higher Order Functions in javascript.
Functions that operate on other functions, either by taking them as arguments or by returning them, are called higher-order functions.
Higher order functions are a result of functions being first-class citizens in javascript.
Examples of higher order functions :
function higherOrder(fn) {
higherOrder(function() { console.log("Hello world") }); 
function higherOrder2() {
  return function() {
    return "Do something";
var x = higherOrder2();
x()   // Returns "Do something"
5 .
What is negative infinity?
Negative Infinity is a number in JavaScript which can be derived by dividing negative number by zero.
6 .
Is it possible to break JavaScript Code into several lines?
Breaking within a string statement can be done by the use of a backslash, '\', at the end of the first line
Example :
document.write("This is \a program");
And if you change to a new line when not within a string statement, then javaScript ignores break in line.
var x=1, y=2,
The above code is perfectly fine, though not advisable as it hampers debugging.
7 .
Write the code for adding new elements dynamically?
	<title>Adding New Elements</title> 
	<script type="text/javascript"> 
	function addNode() { var newP = document.createElement("p"); 
	var textNode = document.createTextNode(" This is a new text node"); 
	newP.appendChild(textNode); document.getElementById("firstP").appendChild	(newP); } 
	<body> <p id="firstP">firstP<p> </body> 
8 .
What are global variables? How are these variable declared and what are the problems associated with using them?
Global variables are those that are available throughout the length of the code, that is, these have no scope. The var keyword is used to declare a local variable or object. If the var keyword is omitted, a global variable is declared.
Example :
// Declare a global globalVariable = "Test";

The problems that are faced by using global variables are the clash of variable names of local and global scope. Also, it is difficult to debug and test the code that relies on global variables.
9 .
In JavaScript, what is ‘This’ keyword?
In JavaScript, the keyword ‘this’ refers to the object it belongs to and gives different values depending upon its usage.
For Example :
* In method – refers own object
* Alone – refers to the global object
* Function – undefined (in strict mode)
10 .
Which symbol is used for comments in Javascript?
// for Single line comments and
/* Multi Line Comment */