Java Script Interview Questions and Answers
Question - 51 : - How to comment javascript code?
Answer - 51 : - Use // for line comments and
/*
*/ for block comments
Name the numeric constants representing max,min values
Number.MAX_VALUE
Number.MIN_VALUE
Question - 52 : - How do you create a new object in JavaScript?
Answer - 52 : - var obj = new Object(); or var obj = {};
How do you assign object properties?
obj["age"] = 17 or obj.age = 17.
Question - 53 : - What does javascript null mean?
Answer - 53 : - The null value is a unique value representing no value or no object.
It implies no object,or null string,no valid boolean value,no number and no array object.
Question - 54 : - What is this keyword?
Answer - 54 : - It refers to the current object.
Question - 55 : - What’s a way to append a value to an array?
Answer - 55 : - arr[arr.length] = value;
Question - 56 : - What does the term sticky session mean in a web-farm scenario? Why would you use a sticky session? What is the potential disadvantage of using a sticky session?
Answer - 56 : - Sticky session refers to the feature of many commercial load balancing solutions for web-farms to route the requests for a particular session to the same physical machine that serviced the first request for that session. This is mainly used to ensure that a in-proc session is not lost as a result of requests for a session being routed to different servers. Since requests for a user are always routed to the same machine that first served the request for that session, sticky sessions can cause uneven load distribution across servers.
You have an ASP.NET web application running on a web-farm that does not use sticky sessions - so the requests for a session are not guaranteed to be served the same machine. Occasionally, the users get error message Validation of viewstate MAC failed. What could be one reason that is causing this error?
The most common reason for this error is that the machinekey value in machine.config is different for each server. As a result, viewstate encoded by one machine cannot be decoded by another. To rectify this, edit the machine.config file on each server in the web-farm to have the same value for machinekey.
To set all checkboxes to true using JavaScript?
//select all input tags
function SelectAll() {
var checkboxes = document.getElementsByTagName("input");
for(i=0;i
Question - 57 : - To set all checkboxes to true using JavaScript?
Answer - 57 : - //select all input tags
function SelectAll() {
var checkboxes = document.getElementsByTagName("input");
for(i=0;i
Question - 58 : - How to select an element by id and swapping an image ? ...
Answer - 58 : -
...
Question - 59 : - What does undefined value mean in javascript?
Answer - 59 : - Undefined value means the variable used in the code doesn't exist or is not assigned any value or the property doesn't exist.
Question - 60 : - What is the difference between undefined value and null value?
Answer - 60 : - (i)Undefined value cannot be explicitly stated that is there is no keyword called undefined whereas null value has keyword called null
(ii)typeof undefined variable or property returns undefined whereas typeof null value returns object