Questions on JavaScript

Jan 11 • Resources • 2035 Views • 5 Comments on Questions on JavaScript

Ques 1. What is JavaScript?
Ans: JavaScript is a general-purpose programming language designed to let programmers of all skill levels control the behaviour of software objects. The language is used most widely today in Web browsers whose software objects tend to represent a variety of HTML elements in a document and the document itself. But the language can be–and is–used with other kinds of objects in other environments. For example, Adobe Acrobat Forms uses this as its underlying scripting language to glue together objects that are unique to the forms generated by Adobe Acrobat. Therefore, it is important to distinguish this programming language, the language, from the objects it can communicate with in any particular environment. When used for Web documents, the scripts go directly inside the HTML documents and are downloaded to the browser with the rest of the HTML tags and content.

Web Application


Ques 2. How is JavaScript different from Java? 
Ans: 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, it relies on whatever environment it’s operating in for the user interface, such as a Web document’s form elements.
This language 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.

Ques 3. What’s relationship between JavaScript and ECMAScript? 
Ans: ECMAScript is yet another name for JavaScript (other names include LiveScript). The current script that you see supported in browsers is ECMAScript revision 3.

Ques 4. How do you submit a form using JavaScript? 
Ans: Use document.forms[0].submit();
(0 refers to the index of the form – if you have more than one form in a page, then the first one has the index 0, second has index 1 and so on).

Ques 5. How do we get JavaScript onto a web page
Ans: You can use several different methods of placing this script in you pages.
You can directly add a script element inside the body of page.
1. For example, to add the “last updated line” to your pages, In your page text, add the following:
<p>blah, blah, blah, blah, blah.</p>
<script type=”text/javascript” >
<!– Hiding from old browsers
document.write(“Last Updated:” +
// –>
<p>yada, yada, yada.</p>

(Note: the first comment, “<–” hides the content of the script from browsers that don’t understand this script. The “// –>” finishes the comment. The “//” tells the language that this is a comment so it doesn’t try to interpret the “–>”. If your audience has much older browsers, you should put this comments inside your code. If most of your audience has newer browsers, the comments can be omitted. For brevity, in most examples here the comments are not shown). The above code will look like this on Javascript enabled browsers.

2. It can be placed inside the <head> element
Functions and global variables typically reside inside the <head> element.
<title>Default Test Page</title>
<script language=”JavaScript” type=”text/javascript”>
var myVar = “”;
function timer(){setTimeout(‘restart()’,10);}

3. It can be referenced from a separate file-
This scripting Language may also a placed in a separate file on the server and referenced from an HTML page. (Don’t use the shorthand ending “<script … />). These are typically placed in the <head> element.
<script type=”text/javascript” SRC=”myStuff.js”></script>

Ques 6. How to read and write a file using javascript? 
Ans: 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.

Ques 7. How to detect the operating system on the client machine? 
Ans: In order to detect the operating system on the client machine, the navigator.appVersion
string (property) should be used.

Ques 8. How can JavaScript make a Web site easier to use? That is, are there certain JavaScript techniques that make it easier for people to use a Web site? 
Ans: JavaScript’s greatest potential gift to a Web site is that scripts can make the page more immediately interactive, that is, interactive without having to submit every little thing to the server for a server program to re-render the page and send it back to the client. For example, consider a top-level navigation panel that has, say, six primary image map links into subsections of the Web site. With only a little bit of scripting, each map area can be instructed to pop up a more detailed list of links to the contents within a subsection whenever the user rolls the cursor atop a map area. With the help of that popup list of links, the user with a scriptable browser can bypass one intermediate menu page. The user without a scriptable browser (or who has disabled this language) will have to drill down through a more traditional and time-consuming path to the desired content.

Ques 9. Explain Event Bubbling?
Ans: In Document Object Model(DOM), the behaviour of events in the child nodes and their parent nodes is defined and described by the EVENT BUBBLING. This means each and every child node is automatically passed onto their parent nodes. This increases the speed due to the single traverse of the DOM Tree. It help in reducing the complexity of the coding in the program.

Ques 10. Is there any difference between Javascript and jQuery?
Ans: jQuery is not so different from JavaScript but at the same time, jQuery is not same as the JavaScript. The jQuery is a fast and more concise JavaScript Library simplifying the traversing process of HTML Documents, handling of Events, AJAX Interaction as well as animations.

Download pdf of the JavaScript Interview Questions and answers here QUESTIONS AND ANSWERS ON JAVASCRIPT.pdf

Related Links-
AJAX (Asynchronous JavaScript and XML)
Interview questions on JAVA
Sample Paper for Java Programming Language

Tell us Your Queries, Suggestions and Feedback

Your email address will not be published.

5 Responses to Questions on JavaScript

  1. Ritika says:

    JAVA Script is meant for all skill programmers, evryone should go through it!

  2. suriya prakash says:

    JavaScript is my favorite scripting language. This questions made me to get more stronger to the language. thanks for the good time.

  3. sakshi chaudhary says:

    JAVA is one of the most important language that is being used in the latest gadgets now a days….this article consists really very useful info about the JAVA Script concept…..

  4. Ankita Prajapati says:

    Prepares you thoroughly with the JAVA SCRIPT concepts….Really Helpfulll…!!!!

  5. Siddhant Tripathi says:

    JAVA is one of the biggest languages in which the mobile and other apps. are developed.
    The content is really helpful in getting cozy with JAVA Script concepts.

« »