get the app get the app       get the app       get the app

Java Script Interview QUESTIONS

Exam NameJava Script Interview QUESTIONS
DescriptionJava Script Interview QUESTIONS contains the questions from various interview of IT industry.These questions are helpful to crack the IT interview.
Exam TypeMASTER EXAM
Authenticity3
creatorPayal(365)

Back to Parent Category
Create QuestionPDF  
.
Question: What would be the output of the following statements?
var object1 = { same: 'same' };
var object2 = { same: 'same' };
console.log(object1 === object2);


Answer:Logs false, JavaScript does not care that they are identical and of the same object type.
When comparing complex objects, they are equal only when they reference the same object (i.e., have the same address). Two variables containing identical objects are not equal to each other since they do not actually point at the same object.


Question: What would be the output of the following statements?
var object1 = { same: 'same' };
var object2 = object1;
console.log(object1 === object2);


Answer:Logs true


Question: Consider the following statements and tell what would be the output of the logs statements?

var price1 = 10;
var price2 = 10;
var price3 = new Number('10'); // A complex numeric object because new was used.
console.log(price1 === price2);
console.log(price1 === price3);


Answer:console.log(price1 === price2); // Logs true.
console.log(price1 === price3); /* Logs false because price3
contains a complex number object and price 1
is a primitive value. */


Question: How you will add function as a property in a JavaScript object? Give an example.

Answer:var man = new Object();
man.name = 'Vikas Ahlawat';
man.living = true;
man.age = 27;
man.getName = function() { return man.name;}
console.log(man.getName()); // Logs 'Vikas Ahlawat'.


Question: How to read and write a file using JavaScript?

Answer:I/O operations like reading or writing a file is not possible with client-side JavaScript. However , this can be done by coding a Java applet that reads files for the script


Question: How can JavaScript be used to personalize or tailor a Web site to fit individual users?

Answer:JavaScript allows a Web page to perform "if-then" kinds of decisions based on browser version, operating system, user input, and, in more recent browsers, details about the screen size in which the browser is running. While a server CGI program can make some of those same kinds of decisions, not everyone has access to or the expertise to create CGI programs. For example, an experienced CGI programmer can examine information about the browser whenever a request for a page is made thus a server so equipped might serve up one page for Navigator users and a different page for Internet Explorer users. Beyond browser and operating system version, a CGI program can't know more about the environment. But a JavaScript-enhanced page can instruct the browser to render only certain content based on the browser, operating system, and even the screen size.

Scripting can even go further if the page author desires. For example, the author may include a preference screen that lets the user determine the desired background and text color combination. A script can save this information on the client in a well-regulated local file called a cookie. The next time the user comes to the site, scripts in its pages look to the cookie info and render the page in the color combination selected previously. The server is none the wiser, nor does it have to store any visitor-specific information.


Question: How is JavaScript different from Java?

Answer:JavaScript was developed by Brendan Eich of Netscape Java was developed at Sun Microsystems. While the two languages share some common syntax, they were developed independently of each other and for different audiences. Java is a full-fledged programming language tailored for network computing it includes hundreds of its own objects, including objects for creating user interfaces that appear in Java applets (in Web browsers) or standalone Java applications. In contrast, JavaScript relies on whatever environment it's operating in for the user interface, such as a Web document's form elements.

JavaScript was initially called LiveScript at Netscape while it was under development. A licensing deal between Netscape and Sun at the last minute let Netscape plug the "Java" name into the name of its scripting language. Programmers use entirely different tools for Java and JavaScript. It is also not uncommon for a programmer of one language to be ignorant of the other. The two languages don't rely on each other and are intended for different purposes. In some ways, the "Java" name on JavaScript has confused the world's understanding of the differences between the two. On the other hand, JavaScript is much easier to learn than Java and can offer a gentle introduction for newcomers who want to graduate to Java and the kinds of applications you can develop with it.


Question: What is negative infinity?

Answer:It’s a number in JavaScript, derived by dividing negative number by zero.


Question: In a pop-up browser window, how do you refer to the main browser window that opened it?

Answer:Use window.opener to refer to the main window from pop-ups.


Question: What does the "Access is Denied" IE error mean?

Answer:The "Access Denied" error in any browser is due to the following reason.
A JavaScript in one window or frame is tries to access another window or frame whose
document's domain is different from the document containing the script.


Question: What’s a way to append a value to an array?

Answer:arr[arr.length] = value;


Question: 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: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.


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

Answer:(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


Question: What is variable typing in JavaScript?

Answer:It is perfectly legal to assign a number to a variable and then assign a string to the same variable as follows
example
i = 10;
i = "string";
This is called variable typing


Question: Does JavaScript have the concept level scope?

Answer:No. Javascript does not have block level scope, all the variables declared inside a function possess the same level of scope unlike c, c++, java.


Question: How to disable an HTML object?

Answer:To disable an HTML object in JavaScript use below line of code'

document.getElementById("myObject").disabled = true;


Question: What is jQuery.noConflict?

Answer:As other client side libraries like MooTools, Prototype can be used with jQuery and they also use $() as their global function and to define variables. This situation creates conflict as $() is used by jQuery and other library as their global function. To overcome from such situations, jQuery has introduced jQuery.noConflict().

jQuery.noConflict();
// Use jQuery via jQuery(')
jQuery(document).ready(function(){
jQuery("div").hide();
});

You can also use your own specific character in the place of $ sign in jQuery.

var $j = jQuery.noConflict();
// Use jQuery via jQuery(')
$j(document).ready(function(){
$j("div").hide();
});



Question: Does events are also copied when you clone any element in jQuery?

Answer:Using clone() method, we can create clone of any element but the default implementation of the clone() method doesn't copy events unless you tell the clone() method to copy the events. The clone() method takes a parameter, if you pass true then it will copy the events as well.

$(document).ready(function(){
$("#btnClone").bind('click', function(){
$('#dvClickme').clone(true).appendTo('body');
});



Question: Is there any difference between body onload() and document.ready() function?

Answer:document.ready() function is different from body onload() function for 2 reasons.

1)We can have more than one document.ready() function in a page where we can have only one body onload function.

2)document.ready() function is called as soon as DOM is loaded where body.onload() function is called when everything gets loaded on the page that includes DOM, images and all associated resources of the page.


Question: What is event.PreventDefault?

Answer:The event.preventDefault() method stops the default action of an element from happening. For example, Prevents a link from following the URL.