This set of JavaScript Interview Questions and Answers focuses on “JavaScript in Web Browsers – II”.
1. What is the property to access the first child of a node?
a) timestamp.Child1
b) timestamp.Child(1)
c) timestamp.Child(0)
d) timestamp.firstChild
View Answer
Explanation: The first child of a node can be accessed using the firstChild property. firstChild returns the first child node as an element node, a text node or a comment node (depending on which one’s first).
2. What are the properties supporting CSS styles for a document element?
a) style and font
b) style and className
c) size and style
d) className and font
View Answer
Explanation: Each Element object has style and className properties that allow scripts to specify CSS styles for a document element or to alter the CSS class names that apply to the element. firstChild returns the first child node as an element node, a text node or a comment node (depending on which one’s first).
3. Which of the following object belongs to the style property?
a) Element
b) Window
c) Location
d) Dynamic
View Answer
Explanation: Each Element object has style and className properties that allow scripts to specify CSS styles for a document element or to alter the CSS class names that apply to the element.
4. What is the purpose of the event handlers in the JavaScript?
a) Adds innerHTML page to the code
b) Performs handling of exceptions and occurrences
c) Allows JavaScript code to alter the behaviour of windows
d) Change the server location
View Answer
Explanation: Event handlers allow JavaScript code to alter the behavior of windows, of documents, and of the elements that make up those documents.
5. Which handler is triggered when the content of the document in the window is stable and ready for manipulation?
a) onload
b) manipulate
c) create
d) onkeypress
View Answer
Explanation: One of the most important event handlers is the onload handler of the Window object. It is triggered when the content of the document displayed in the window is stable and ready to be manipulated. JavaScript code is commonly wrapped within an onload event handler.
6. When a program contains extensive use of event handlers, which of the following is necessary?
a) Modular functions
b) Nested functions
c) Split up programs
d) Global variables
View Answer
Explanation: Nested functions are those functions in which one function is defined inside another function. Nested functions are common in client-side JavaScript, because of its extensive use of event handlers.
7. What is the JavaScript code snippet to find all container elements with class “reveal”?
a) var elements = document.getElementsByClassName(“reveal”);
b) var elements = document.getElementByClassName(“reveal”);
c) var elements = document.getElementByName(“reveal”);
d) var elements = document.getElementsClassName(“reveal”);
View Answer
Explanation: The getElementsByClassName() method returns a collection of all elements in the document with the specified class name, as a NodeList object. The above code snippet finds all container elements with class “reveal”.
8. What is the JavaScript code snippet to update the content of the timestamp element when the user clicks on it?
a) timestamp.onLoad = function() { this.innerHTML = new Date().toString(); }
b) timestamp.onclick = function() { this.innerHTML = new Date().toString(); }
c) timestamp.onload = function() { this.innerHTML = new Date().toString(); }
d) timestamp.onclick = function() { innerHTML = new Date().toString(); }
View Answer
Explanation: onclick() function is used to handle events when the user clicks on the mouse. The above code snippet updates the content of the timestamp element when the user clicks on it.
9. Which of the following is not an object?
a) Element
b) Location
c) Position
d) Window
View Answer
Explanation: There is no object called Position. Whereas elements, location and window are a predefined object in JavaScript.
10. What is the JavaScript code snippet to change the class and let the stylesheet specify the details?
a) timestamp.className = “highlight”;
b) timestamp.className = “change”;
c) timestamp.className = “specify”;
d) timestamp.className = “move”;
View Answer
Explanation: Each Element object has style and className properties that allow scripts to specify CSS styles for a document element or to alter the CSS class names that apply to the element. The above code snippet changes the class and lets the stylesheet specify the details.
Sanfoundry Global Education & Learning Series – Javascript Programming.
- Apply for Computer Science Internship
- Check JavaScript Books
- Practice Programming MCQs
- Check Programming Books
- Practice MCA MCQs