This set of JavaScript Problems focuses on “Cache Variables and Properties across Scope”.
1. What does the interpreter do when you reference variables in other scopes?
a) Traverses the queue
b) Traverses the stack
c) Finds the bugs
d) Traverse the array
View Answer
Explanation: The interpreter executes the javascript code. Normally when you reference variables in other scopes at the global level, in other namespaces, and so on—the interpreter needs to traverse the stack to get to the variable.
2. The attribute location belongs to which element?
a) document
b) html
c) image
d) pre
View Answer
Explanation: window.location.href returns the href (URL) of the current page. The attribute location belongs to the document element.
3. What will happen if you reference document.location from within an object?
a) Traverses the queue
b) Finds the bugs
c) Traverses the stack
d) Traverses the array
View Answer
Explanation: window.location.href returns the href (URL) of the current page. If you reference document.location from within an object, the interpreter will need to go from the function that references the variable, up out of the namespace to the global window scope, down to the document scope, and gets the location value.
4. Why do we need to create locally scoped variables to hold value?
a) To optimize the testing process
b) To increase the speed
c) To minimize memory usage
d) To cache the reference document.location
View Answer
Explanation: window.location.assign loads a new document. The locally scoped variables are created to cache the reference to document.location.
5. What is the next step after calling the startTimeLogging()?
a) Interpret the code
b) Compile the code
c) Run the code
d) Debug the code
View Answer
Explanation: The startTimeLogging() method captures the timing data for ad hoc, etc for referencing an uncached document.location. Once the startTimeLogging() method is called, run the code to test.
6. During the traversing through the stack, where does it go after it goes to the namespace?
a) Window
b) Function
c) Document
d) Location
View Answer
Explanation: Namespace in JavaScript is nothing but a single global object which will contain all our functions, methods, variables and all that. During the traversal in the stack manner, after going to the namespace, it goes to the Window.
7. During the traversing through the stack, where does it go after it goes to the window?
a) Namespace
b) Function
c) Document
d) Nowhere
View Answer
Explanation: window.location.assign loads a new document. During the traversal in the stack manner, after going to the window, it goes nowhere.
8. During the traversing of the stack when you create a locally scoped variable, where does it go after it goes to the namespace?
a) Window
b) Function
c) Document
d) Location
View Answer
Explanation: Namespace in JavaScript is nothing but a single global object which will contain all our functions, methods, variables and all that. When you create a locally scoped variable for caching the reference, the traversal reverses in the forward direction and thus, after going to the namespace, it goes to the function.
9. What is the function used to stop capturing the ad hoc timing ?
a) stopadhoc()
b) stopTimer()
c) stopTimeLogging()
d) stophoc()
View Answer
Explanation: The startTimeLogging() method captures the timing data for ad hoc, etc for referencing an uncached document.location. In order to stop capturing the ad hoc timing for referencing uncached document.location, we call the method stopTimeLogging().
10. During the traversing of the stack when you create a locally scoped variable, where does it go after it goes to the location?
a) Window
b) Function
c) Document
d) Nowhere
View Answer
Explanation: window.location.assign loads a new document. When you create a locally scoped variable for caching the reference, the traversal reverses in the forward direction and thus, after going to the location, it goes nowhere.
Sanfoundry Global Education & Learning Series – Javascript Programming.
- Apply for Computer Science Internship
- Practice Information Science MCQs
- Practice Programming MCQs
- Check JavaScript Books
- Check Programming Books