• +91 9971497814
  • info@interviewmaterial.com

Computer Interview Questions Answers

Java Script Interview Questions Answers

Question - 1 : - What is the difference between SessionState and ViewState?

Answer - 1 : - ViewState is specific to a page in a session. Session state refers to user specific data that can be accessed across all pages in the web application.

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

Answer - 2 : - 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 - 3 : - How to disable an HTML  object ?

Answer - 3 : - document.getElementById("myObject").disabled = true; To write messages to the screen without using "document.write()" ? Changing the contents of an element is a much better solution. When the method showStatus is invoked it will change the content of the span. ... function showStatus(message) { var element = document.getElementById("mystatus"); element.textContent = message; //for Firefox element.innerHTML = message; //for IE (why can't we all just get along?) return true; } ... <span id="mystatus">Test. </span> ...

Question - 4 : - Are Java and JavaScript the Same?

Answer - 4 : - No.java and javascript are two different languages. Java is a powerful object - oriented programming language like C++,C whereas Javascript is a client-side scripting language with some limitations.

Question - 5 : - What does the EnableViewStateMac setting in an aspx page do?

Answer - 5 : - Setting EnableViewStateMac=true is a security measure that allows ASP.NET to ensure that the viewstate for a page has not been tampered with. If on Postback, the ASP.NET framework detects that there has been a change in the value of viewstate that was sent to the browser, it raises an error - Validation of viewstate MAC failed. Use <%@ Page EnableViewStateMac="true"%> to set it to true (the default value, if this attribute is not specified is also true) in an aspx page.

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

Answer - 6 : - arr[arr.length] = value;

Question - 7 : - How to determine the state of a checkbox using Javascript?

Answer - 7 : - var checkedP = window.document.getElementById("myCheckBox").checked;

Question - 8 : - How to create a confirmation box?

Answer - 8 : - confirm("Do you really want to launch the missile?");

Question - 9 : - How is JavaScript different from Java?

Answer - 9 : - 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 - 10 : - How to create arrays in JavaScript?

Answer - 10 : - We can declare an array like this var scripts = new Array(); We can add elements to this array like this scripts[0] = "PHP"; scripts[1] = "ASP"; scripts[2] = "JavaScript"; scripts[3] = "HTML"; Now our array scrips has 4 elements inside it and we can print or access them by using their index number. Note that index number starts from 0. To get the third element of the array we have to use the index number 2 . Here is the way to get the third element of an array. document.write(scripts[2]); We also can create an array like this var no_array = new Array(21, 22, 23, 24, 25);

Computer Contributors

Rajeev Katiyar
Yes Baroda

Share your email for latest updates


Our partners