JavaScript Interview Questions and Answers for
What is JavaScript?
JavaScript is a client-side as well as server side scripting language that can be inserted into HTML pages and is understood by web browsers. JavaScript is also an Object based Programming language
Differences between declaring variables using var, let and const.
var declarations are globally scoped or function scoped while let and const are block scoped. var variables can be updated and re-declared within its scope; let variables can be updated but not re-declared; const variables can neither be updated nor re-declared. They are all hoisted to the top of their scope.
What is difference between Null and Undifine or Nan
null is an assigned value. It means nothing. undefined means a variable has been declared
but not defined yet nan is not a number if you divide integer to strings then you get Nan
What is DOM?
DOM stands for Document Object Model.
DOM is a programming interface for HTML and XML documents.
When the browser tries to render a HTML document, it creates an object based on the HTML document called DOM. Using this DOM, we can manipulate or change various elements inside the HTML document.
Example of how HTML code gets converted to DOM:
What is JSON?
JavaScript Object Notation
JSON is a format for storing and transporting data.
JSON is often used when data is sent from a server to a web page.
What is closure in javascript:-
Closure is inner function that has access to the outer function variable
What Is ajax
AJAX = Asynchronous JavaScript And XML.
AJAX allows web pages to be updated asynchronously by exchanging data with a web server behind the scenes. This means that it is possible to update parts of a web page, without reloading the whole page.
function loadDoc() {
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
document.getElementById("demo").innerHTML = this.responseText;
}
};
xhttp.open("GET", "ajax_info.txt", true);
xhttp.send();
}
Whati is && and ||
&& both condition should be true
|| both condition should be true and 1 condition should be true
What is Web API?
Examples:
Application program interface
YouTube API - Allows you to display videos on a web site.
Twitter API - Allows you to display Tweets on a web site.
Facebook API - Allows you to display Facebook info on a web site.
What is prototype in java script:
Prototype is help to obj to create multiple object use constructor
its included default in java script
What is the rest parameter and spread operator?
Both rest parameter and spread operator were introduced in the ES6 version of javascript.
Rest parameter ( … )
Any number of arguments will be converted into an array using the rest parameter.
Rest parameter can be used by applying three dots (...) before the parameters.
What is classes
Class methods are created with the same syntax as object methods.
Use the keyword class to create a class.
Always add a constructor() method.
What Is Hoisting?
Hoisting is a JavaScript mechanism where variables and function declarations are moved to the top of their scope before code execution.
what is JavaScript Closures
JavaScript variables can belong to the local or global scope.
Global variables can be made local (private) with closures.
What is difference between forEach and forloop;
the forEach method is a little cleaner than the for loop.In a forEach method, we pass each food type within that iteration into the callback. A for loop needs you to access the array using a temporary i variable. While
might not seem very messy in the beginning, it can get more cluttered when you begin to add more code.
What Is Promise?
Fulfilled= resolve
Rejected= reject
fetch(url)
then(process)
then(save)
catch(handleErrors)
What are JavaScript Data Types?
Following are the JavaScript Data types:
• Number
• String
• Boolean
• Object
• Undefined
What is the use of isNaN function?
• isNan function returns true if the argument is not a number otherwise it is false.
What is negative infinity?
• Negative Infinity is a number in JavaScript which can be derived by dividing negative number by zero.
What is 'this' keyword in JavaScript?
This' keyword refers to the object from where it was called.
Explain the working of timers in JavaScript? Also elucidate the drawbacks of using the timer, if any?
Timers are used to execute a piece of code at a set time or also to repeat the code in a given interval of time. This is done by using the functions setTimeout, setInterval and clearInterval.
The setTimeout(function, delay) function is used to start a timer that calls a particular function after the mentioned delay. The setInterval(function, delay) function is used to repeatedly execute the given function in the mentioned delay and only halts when cancelled. The clearInterval(id) function instructs the timer to stop.
Timers are operated within a single thread, and thus events might queue up, waiting to be
How can you convert the string of any base to integer in JavaScript?
what is call back function?
Explain the difference between "==" and "==="?
"==" checks only for equality in value whereas "===" is a stricter equality test and returns false if either the value or the type of the two variables are different.
What would be the result of 3+2+"7"?
Since 3 and 2 are integers, they will be added numerically. And since 7 is a string, its concatenation will be done. So the result would be 57.
What do mean by NULL in Javascript?
The NULL value is used to represent no value or no object. It implies no object or null string, no valid boolean value, no number and no array object.
What is the use of Void(0)?
Void(0) is used to prevent the page from refreshing and parameter "zero" is passed while calling.
Void(0) is used to call another method without refreshing the page.
What are the different types of errors in JavaScript?
There are three types of errors:
• Load time errors: Errors which come up when loading a web page like improper syntax errors are known as Load time errors and it generates the errors dynamically.
• Run time errors: Errors that come due to misuse of the command inside the HTML language.
• Logical Errors: These are the errors that occur due to the bad logic performed on a function which is having different operation.
Describe the properties of an anonymous function in JavaScript?
var anon = function() {
alert('I am anonymous');
};
anon();
What boolean operators can be used in JavaScript?
The 'And' Operator (&&), 'Or' Operator (||) and the 'Not' Operator (!) can be used in JavaScript.
*Operators are without the parenthesis.
what is empty array
var str = [1,3,5,6];
str = [];
console.log(str)
what is anonymous function what is the use of javascript
anonymous function has no name between the function keyword and parentheses () . Because we need to call the anonymous function later, we assign the function to the show variable.
Var a = function(){
Document.write(“welcom”)
}
A()
What's the difference between call and apply and bind `?
Fundamental difference is that call() accepts an argument list, while apply() accepts a single array of arguments. The difference is that call() takes the function arguments separately, and apply() takes the function arguments in an array.
Difference between call() and apply() method: The only difference is call() method takes the arguments separated by comma while apply() method takes the array of arguments.
bind(something) returns a new function, in which references to this will refer to something . This is a way of saving the current value of this , which is in scope during the call to the constructor, so that it can be used later when the function is called
What are undeclared and undefined variables?
Undeclared variables are those that do not exist in a program and are not declared. If the program tries to read the value of an undeclared variable, then a runtime error is encountered.
Undefined variables are those that are declared in the program but have not been given any value. If the program tries to read the value of an undefined variable, an undefined value is returned.
Write the code for adding new elements dynamically?
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); }
What is the use of Void (0)?
Void(0) is used to prevent the page from refreshing, and parameter "zero" is passed while calling.
Void(0) is used to call another method without refreshing the page.
What are JavaScript Cookies?
Cookies are the small test files stored in a computer, and they get created when the user visits the websites to store information that they need. Examples could be User Name details and shopping cart information from previous visits.
What a pop()method in JavaScript is?
The pop() method is similar to the shift() method, but the difference is that the Shift method works at the array's start. The pop() method takes the last element off of the given array and returns it. The array on which it is called is then altered.
Example:
var cloths = ["Shirt", "Pant", "TShirt"];
cloths.pop();
//Now cloth becomes Shirt,Pant
What is the use of the Push method in JavaScript?
The push method is used to add or append one or more elements to an Array end. Using this method, we can append multiple elements by passing multiple arguments.
What is the unshift method in JavaScript?
Unshift method is like the push method, which works at the beginning of the array. This method is used to prepend one or more elements to the beginning of the array.
what is opps in javascript
Monday, April 19, 2021
Subscribe to:
Post Comments (Atom)




No comments:
Post a Comment