26. How to get an element by class in JavaScript?
By using method Document.getElementsByclass name(), we can get elements in class name.
27. What is closure?
The closure is a primary mechanism to private the data items. Closures give access to the outer function’s scope from the inner function scope. Closures are created for every function in JavaScript. To define a closure, create a function inside another function to expose it.
28. What is the “===” operator?
“===” is a strict equality operator, returns a true value, if the two operands have the same value.
29. How can we read the properties of JavaScript?
Using dot(.) notation we can read and write the properties of JS.
30. What is the difference between Attributes and properties?
- Attributes- Attributes provide the information about the details given to objects like name, age, id, etc,
- Properties- Properties give information about the values given to the objects.
31. What are the possible ways to define a variable in JavaScript?
There are three possible ways to declare a variable in JavaScript are:
- Var- variables and values of variables can be declared to the Variable statement by Variable statement. Example - var b = 20;. Declaration of variables should be done before the execution of code.
- Const- A constant variable is assigned with one value only once before the execution of code.
- let- If let statements are used in the variable declaration, the variable values can be reassigned before the execution of code.
32. What are the terms BOM and DOM in JavaScript?
- BOM- BOM is a Browser Object Model, in which the window object is supported by all the browsers. The JavaScript objects, variables, and functions also become members of the window object. This model deals with the objects of browsers like location, navigator, history, and screen.
- DOM- DOM is a Document Object Model in JavaScript that helps to access document and HTML elements. When a web page is loaded the browser creates a DOM for the page. All the objects on the page all arranged in order.
33. Explain the terms array slice() and array splice()?
- Array slice() method removes the array items from the array and reforms the removed items into a new array. The selected items through an array slice() method are removed from the array and formed as another new array.
- array splice() method removes the items of the selected array from the array and does not form another array.
34. Define some of the methods in JavaScript?
- confirm() - Helps to get confirm dialog box including messages.
- open() - Helps to open the new window.
- alert() - This method displays the alert box with messages
- close() - Heps to close the window.
- setTimeout() - This method helps to perform certain operations after a specified time like evaluating expressions and calling functions.
35. Explain what is NaN() function?
A NAN (not a number) method is used to return a true value if the variable has no number.
function number(num)
{
if(isNaN(num))
{
returns if it is not a number;
}
return if it is a number;
}
36. Explain View state and Session state?
- View State- The particular point of time where the user spent on only a page of the session is called view state
- Session State- Where the browser or user spends on all pages of the application is called session state.
37. How to make an array empty?
Let us consider an array
Var array = [ “1”, “2”, “3,'' “4” ];
We consider four methods to empty an array
1. array = []
2. array.length = 0;
3. array.splice(0, array.length);
4. while (array.length)
{
array.pop();
}
38. Define the mechanism of the type of operator?
The type of operator is basically just the unary operator that is used before the single operand. The value indicates the operand's data type. The type includes Boolean, number, and string.
JavaScript Interview Questions for Experienced
39. Explain about MUL function in JavaScript?
MUL is a multiplication function. The multiplication of numbers can be done as a value is defined in the function and the value is returned by another function and the process goes on.
Example:
function mul(a)
{
return function(b)
{
return function(c)
{
return a*b*c;
};
};
}
40. Can redirection of a page is possible in JavaScript?
Redirection of the page is possible in JavaScript. By using two ways we can redirect a page to other pages, they are:
- Location.href- This is one of the ways to redirect a page. By this, we can get back access to the document.
window.location.href = (“http//jaquar.com”);
- Location.replace- In this, we can’t get access back the actual document.
window.location.href = (“http//jaquar.com”);
41. How to add and remove properties from objects?
By using,object.property_name The = value we can add a property to the JS object
By using, deleteobject.property_name is used to remove the property from the JS object.
42. How to Validate a form in JavaScript?
We can validate a variable by using the following script
<script>
function validateform()
{
var fullname = document.firstform.fullname.val;
var pwd = document.pwd.val;
if(fullname==null || fullname=="")
{
alert("fullname should be filled")
return true;
}
else if(password.length<5)
alert("pwd must me upto 5 characters long"):
return false;
}
}
</script>
<body>
<form name =" firstform" method= "post" action ="xyz.jpg" onsubmit =" return validateform()">
fullname = input type= "text" fullname ="name">
<br/>
pwd = inputtype="pwd" name="pw">
<br/>
<inputtype="submit"value"register">
</body>
</form>
43. How to represent the date object in JavaScript?
Date object in JavaScript helps to get information about the day, month, and year. By using date object we can set the timer on the screen.
function display()
{
var date = new date();
var day = date.getday();
var month= date.getmonth()+1;
Var year = date.getyear();
doc.write("date is: "+day+"/"+month+"/"+year+");
}
display();
44. What is meant by the debugger in JavaScript?
Debugger keyword in JavaScript helps in setting a breakpoint in the code itself. The program will stop executing code where the debugger keyword is applied in the program.
function display()
{
a = 10;
b = 20;
c = a+b;
debugger;
doc.write(c);
doc.write(a);
}
display();
45. What is the use of a Weakmap object in JavaScript?
Weakmap is similar to a collection of objects like a map. If the weak map object is set to a process, it considers each element as a key object and that key object will have a weak reference.
function display()
{
var wm = new WeakMap();
var object1 = {};
var object2 = {};
var object3 = {};
wm.set(object1, "AngularJS");
wm.set(object2, "ReactJS");
wm.set(object3, "VueJS");
doc.writeIn(wm.has(object3));
}
display();
46. Name some of the JavaScript frameworks?
The applications written in JavaScript are known as JavaScript frameworks. These frameworks are a different form of JavaScript libraries and flows. Here is a list of some important frameworks, they are:
47. Explain about escape characters?
Espace characters are used to handle the special characters without breaking the code in javascript. It uses a black slash for different characters like single and double quotes, newline, and so on
- ’ single quote
- backslash
- ’’ double quote
- n newline
- b backspace
- t tab
- f form feed
48. Write about number objects?
Number objects help to represent the number of values to the variables. The values may be floating-point or integer. In JavaScript, the floating points are represented by using the IEEE standard.
function display()
{
var a = 10;
var b = 0.7;
var c = 11d5;
doc.write(a+" "+b+" "+c+");
}
display();
49. How set object is used in JavaScript?
Set objects are used to store different values to the elements. The values may be reference or primitive values.
function display()
{
var set = new Set();
set.add( "Angular JS":;
set.add(" Vue");
set.add("React JS);
for(set the elements of set)
{
doc.writeIn(elements):
}
}
display();
50. How to calculate the Fibonacci series in JavaScript?
Fibonacci series is a series of numbers, in which every value is the sum of the preceding two numbers starting with 0 and 1.
Example - 0,1,1,2,3,5,8,13,21,34……..
function fibonacci(n);
{
var x=o, y=1;
for (var i=0; i < n; i++);
{
var temp = x+y;
x = y;
y = temp;
}
return x;
}