What is the way to get the status of a CheckBox?
The status can be acquired as follows –
alert(document.getElementById(‘checkbox1′).checked);
If the CheckBox will be checked, this alert will return TRUE.
How can the OS of the client machine be detected?
The navigator.appVersion string can be used to detect the operating system on the client machine.
Explain window.onload and onDocumentReady?
The onload function is not run until all the information on the page is loaded. This leads to a substantial delay before any code is executed.
onDocumentReady loads the code just after the DOM is loaded. This allows early manipulation of the code.
How will you explain closures in JavaScript? When are they used?
Closure is a locally declared variable related to a function which stays in memory when the function has returned.
For example:
function greet(message) {
console.log(message);
}
function greeter(name, age) {
return name + " says howdy!! He is " + age + " years old";
}
// Generate the message
var message = greeter("James", 23);
// Pass it explicitly to greet
greet(message);
This function can be better represented by using closures
function greeter(name, age) {
var message = name + " says howdy!! He is " + age + " years old";
return function greet() {
console.log(message);
};
}
// Generate the closure
var JamesGreeter = greeter("James", 23);
// Use the closure
JamesGreeter();
How can a value be appended to an array?
A value can be appended to an array in the given manner –
arr[arr.length] = value;
Explain the for-in loop?
The for-in loop is used to loop through the properties of an object.
The syntax for the for-in loop is –
for (variable name in object){
statement or block to execute
}
In each repetition, one property from the object is associated to the variable name, and the loop is continued till all the properties of the object are depleted.
Describe the properties of an anonymous function in JavaScript?
A function that is declared without any named identifier is known as an anonymous function. In general, an anonymous function is inaccessible after its declaration.
Anonymous function declaration –
var anon = function() {
alert('I am anonymous');
};
anon();
What is the difference between .call() and .apply()?
The function .call() and .apply() are very similar in their usage except a little difference. .call() is used when the number of the function’s arguments are known to the programmer, as they have to be mentioned as arguments in the call statement. On the other hand, .apply() is used when the number is not known. The function .apply() expects the argument to be an array.
The basic difference between .call() and .apply() is in the way arguments are passed to the function. Their usage can be illustrated by the given example.
var someObject = {
myProperty : 'Foo',
myMethod : function(prefix, postfix) {
alert(prefix + this.myProperty + postfix);
}
};
someObject.myMethod('<', '>'); // alerts '<Foo>'
var someOtherObject = {
myProperty : 'Bar'
};
someObject.myMethod.call(someOtherObject, '<', '>'); // alerts '<Bar>'
someObject.myMethod.apply(someOtherObject, ['<', '>']); // alerts '<Bar>'
Define event bubbling?
JavaScript allows DOM elements to be nested inside each other. In such a case, if the handler of the child is clicked, the handler of parent will also work as if it were clicked too.
Is JavaScript case sensitive? Give an example?
Yes, JavaScript is case sensitive. For example, a function parseInt is not same as the function Parseint.
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.
How can a particular frame be targeted, from a hyperlink, in JavaScript?
This can be done by including the name of the required frame in the hyperlink using the ‘target’ attribute.
<a href=”newpage.htm” target=”newframe”>>New Page</a>
What is the role of break and continue statements?
Break statement is used to come out of the current loop while the continue statement continues the current loop with a new recurrence.
Write the point of difference between web-garden and a web-farm?
Both web-garden and web-farm are web hosting systems. The only difference is that web-garden is a setup that includes many processors in a single server while web-farm is a larger setup that uses more than one server.
What is AJAX Control Extender Toolkit?
AJAX Control Toolkit is one of the extenders that are used to extend or add the functionalities of the ASP.NET controls. The extenders use a block of JavaScript code to add new and enhanced capabilities to the ASP.NET controls.
AJAX Control Extender Toolkit is a free download from site.
Where AJAX cannot be used?
Users cannot use AJAX if
If Page need to show in a search engine
If browser does not support JavaScript
If user wants to create secure application
What are the difference between AJAX and Javascript?
The differences between AJAX and JavaScript are as follows:
AJAX
Javascript
AJAX sends request to the server and does not wait for the response. It performs other operations on the page during that time JavaScript make a request to the server and waits for response
AJAX does not require the page to refresh for downloading the whole page JavaScript manages and controls a Web page after being downloaded
AJAX minimizes the overload on the server since the script needs to request once JavaScript posts a request that updates the script every time.
The status can be acquired as follows –
alert(document.getElementById(‘checkbox1′).checked);
If the CheckBox will be checked, this alert will return TRUE.
How can the OS of the client machine be detected?
The navigator.appVersion string can be used to detect the operating system on the client machine.
Explain window.onload and onDocumentReady?
The onload function is not run until all the information on the page is loaded. This leads to a substantial delay before any code is executed.
onDocumentReady loads the code just after the DOM is loaded. This allows early manipulation of the code.
Baidu Most Frequently Asked Latest JavaScript Interview Questions Answers |
How will you explain closures in JavaScript? When are they used?
Closure is a locally declared variable related to a function which stays in memory when the function has returned.
For example:
function greet(message) {
console.log(message);
}
function greeter(name, age) {
return name + " says howdy!! He is " + age + " years old";
}
// Generate the message
var message = greeter("James", 23);
// Pass it explicitly to greet
greet(message);
This function can be better represented by using closures
function greeter(name, age) {
var message = name + " says howdy!! He is " + age + " years old";
return function greet() {
console.log(message);
};
}
// Generate the closure
var JamesGreeter = greeter("James", 23);
// Use the closure
JamesGreeter();
How can a value be appended to an array?
A value can be appended to an array in the given manner –
arr[arr.length] = value;
Explain the for-in loop?
The for-in loop is used to loop through the properties of an object.
The syntax for the for-in loop is –
for (variable name in object){
statement or block to execute
}
In each repetition, one property from the object is associated to the variable name, and the loop is continued till all the properties of the object are depleted.
Describe the properties of an anonymous function in JavaScript?
A function that is declared without any named identifier is known as an anonymous function. In general, an anonymous function is inaccessible after its declaration.
Anonymous function declaration –
var anon = function() {
alert('I am anonymous');
};
anon();
What is the difference between .call() and .apply()?
The function .call() and .apply() are very similar in their usage except a little difference. .call() is used when the number of the function’s arguments are known to the programmer, as they have to be mentioned as arguments in the call statement. On the other hand, .apply() is used when the number is not known. The function .apply() expects the argument to be an array.
The basic difference between .call() and .apply() is in the way arguments are passed to the function. Their usage can be illustrated by the given example.
var someObject = {
myProperty : 'Foo',
myMethod : function(prefix, postfix) {
alert(prefix + this.myProperty + postfix);
}
};
someObject.myMethod('<', '>'); // alerts '<Foo>'
var someOtherObject = {
myProperty : 'Bar'
};
someObject.myMethod.call(someOtherObject, '<', '>'); // alerts '<Bar>'
someObject.myMethod.apply(someOtherObject, ['<', '>']); // alerts '<Bar>'
Define event bubbling?
JavaScript allows DOM elements to be nested inside each other. In such a case, if the handler of the child is clicked, the handler of parent will also work as if it were clicked too.
Is JavaScript case sensitive? Give an example?
Yes, JavaScript is case sensitive. For example, a function parseInt is not same as the function Parseint.
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.
How can a particular frame be targeted, from a hyperlink, in JavaScript?
This can be done by including the name of the required frame in the hyperlink using the ‘target’ attribute.
<a href=”newpage.htm” target=”newframe”>>New Page</a>
What is the role of break and continue statements?
Break statement is used to come out of the current loop while the continue statement continues the current loop with a new recurrence.
Write the point of difference between web-garden and a web-farm?
Both web-garden and web-farm are web hosting systems. The only difference is that web-garden is a setup that includes many processors in a single server while web-farm is a larger setup that uses more than one server.
What is AJAX Control Extender Toolkit?
AJAX Control Toolkit is one of the extenders that are used to extend or add the functionalities of the ASP.NET controls. The extenders use a block of JavaScript code to add new and enhanced capabilities to the ASP.NET controls.
AJAX Control Extender Toolkit is a free download from site.
Where AJAX cannot be used?
Users cannot use AJAX if
If Page need to show in a search engine
If browser does not support JavaScript
If user wants to create secure application
What are the difference between AJAX and Javascript?
The differences between AJAX and JavaScript are as follows:
AJAX
Javascript
AJAX sends request to the server and does not wait for the response. It performs other operations on the page during that time JavaScript make a request to the server and waits for response
AJAX does not require the page to refresh for downloading the whole page JavaScript manages and controls a Web page after being downloaded
AJAX minimizes the overload on the server since the script needs to request once JavaScript posts a request that updates the script every time.
Post a Comment