Javascript Interview Questions and answers for 1-3 years experienced

Javascript Interview Questions and answers for 1-3 years experienced
Here is the list of javascript questions and answers which will help you during interview time.The frequently asked JavaScript interview questions with answers for beginners and professionals are given below.



javascript-interview-questions-answers

Question: What are JavaScript types?

Following are the JavaScript types:
1.Number
2.String
3.Boolean
4.Object
5.Null
6.Function
7.Undefined

Question: Is JavaScript a case-sensitive language?

Yes! JavaScript is a case-sensitive language. This means that language keywords, variables, function names, and any other identifiers must always be typed with a consistent capitalization of letters.

Question: How can you create an Object in JavaScript?

This example will show you how to create Object in JavaScript

var myInfo = {
   name: "Rohit Kumar",
   email: "[email protected]"
};

Question: What is negative infinity?

Negative Infinity is a number in JavaScript which can be derived by dividing negative number by zero.

Question: How to convert a string to lowercase?

var str='MY Public Notebook';
str = str.toLowerCase();
console.log(str);



Question: How to modify the URL of page without reloading the page?

window.history.pushState('newPage', 'This is new page title', '/newpage.php');

Question: What is DOM? What is the use of document object?

DOM stands for Document Object Model. A document object represent the html document. It can be used to access and change the content of html.

Question: What is Pop() method in JavaScript?

The pop() method take the last element off of the given array and returns it. The array on which is called is then altered.

var fruits = ["apple ", "banana ", "mango"]; 
fruits.pop();
console.log(fruits);

Question: How can you read properties of an Object in JavaScript?

// Setting object properties
myInfo.name = "Rohit Kumar" ; 
myInfo.email  =  "[email protected]" ;    
 
// Getting object properties
myInfo.name  // Output: Rohit kumar
myInfo.email   // ==> Output: [email protected]

Question: What is encodeURI() function?

encodeURI() function is used to encode the URI.

var uri = “emp.php?Emp=rohit&mode=add”;
console.log(encodeURI(uri) );

Question: Which company developed JavaScript?

Netscape is the software company who developed JavaScript.

Question: What is a prompt box?

A prompt box is a box which allows the user to enter input by providing a text box. Label and box will be provided to enter the text or number.

Question: Which symbol is used for comments in Javascript?

// for Single line comments 
 
/*  For  Multi
Line
Comments
*/



Question: What is === operator?

=== is called as strict equality operator which returns true when the two operands are having the same value without any type conversion.

Question: How can you submit a form using JavaScript?

To submit a form using JavaScript use document.form[0].submit();

document.form[0].submit();

Question: How to convert JSON Object to String?

var name=['My','public','Notebook']
console.log(JSON.stringify(name));

Question: How to convert JSON String to Object?

var name=['My','public','Notebook']
console.log(JSON.parse(name));

Question: How to open URL in new tab in javascript?

window.open('http://www.iamrohit.in','_blank');

Question: How to get current date in JavaScript?

var today = new Date();
console.log(today);

Question: What is unescape() function?

The unescape() function is used to decode the encoded string.

document.write(unescape(“Answer%3F%20Get%20from%20us%21”));

Question: How can the style/class of an element be changed?

The unescape() function is used to decode the encoded string.

document.getElementById(“#myId”).style.color = "red";
//OR
document.getElementById(“myId”).className =class;

Question: What are all the looping structures in JavaScript?

Following are looping structures in Javascript:

1.For
2.While
3.do-while loops

Question: How can you create an Array in JavaScript?

By below method

var x = [];
var y = [1, 2, 3, 4, 5];

Question: What is callback?

A callback is a plain JavaScript function passed to some method as an argument or option. Some callbacks are just events, called to give the user a chance to react when a certain state is triggered.

Question: What is closure?

Closures are created whenever a variable that is defined outside the current scope is accessed from within some inner scope.

Question: What are all the types of Pop up boxes available in JavaScript?

Following are..
1.Alert
2.Confirm and
3.Prompt

Question: What is the data type of variables of in JavaScript?

All variables in the JavaScript are object data types.

Question: How do I declare a namespace in JavaScript?

By below method

var myNamespace = {
 
    functionOne: function() {   },
 
    functionTwo: function() {    }
 
};
 
myNamespace.functionTwo();

Question: What is the difference between == and ===?

The == operator checks equality only whereas === checks equality and data type i.e. value must be of same type.


Question: How to write normal text code using JavaScript dynamically?

document.getElementById('mylocation').innerText="My public notebook";

Question: What does the isNaN() function?

The isNan() function returns true if the variable value is not a number.

Question: What is the difference between undefined value and null value?

Undefined value: A value that is not defined and has no keyword is known as undefined value.
Null value: A value that is explicitly specified by the keyword “null” is known as null value.

Question: How to set the cursor to wait in JavaScript?

By below method

window.document.body.style.cursor = "wait";

Question: How to handle exceptions in JavaScript?

By the help of try/catch block, we can handle exceptions in JavaScript. JavaScript supports try, catch, finally and throw keywords for exception handling.

Question: Which built-in method returns the length of the string?

length() method returns the length of the string.

var str = "My public notebook";
console.log(str.length);

If You have more javascript question and answer then you can post these questions and answers in the comment box and help others.

If you like this post please don’t forget to subscribe my public notebook for more useful stuff