Java MCQ Set 1
1. In which format does JavaScript support external JavaScript?
a) .js
b) .php
c) .js/php
d) .jss
Answer
Answer: a [Reason:] JavaScript supports external JavaScript, in the form of .js file.
2. What are the two parts of JavaScript libraries?
a) “script” tag and “body” tag
b) External JavaScript and the “script” tag
c) “html” tag and “body” tag
d) None of the mentioned
Answer
Answer: b [Reason:] All JavaScript libraries consists of two parts:
- The external JavaScript itself, which is simply a text file with the containing JavaScript code, saved as a .js file.
- A “script” tag referencing the external JavaScript file and defined on the page(s) that uses the library.
3. Which of the following is added to prefs.js when the console is automatically opened during JavaScript error?
a) user_pref("javascript.console.open_on_error", true); b) user_pref("javascript.console.open_error ", true); c) user_pref("javascript.console.open_error ", false); d) user_pref(" javascript.console.open_on_error", false);
Answer
Answer: a [Reason:] The code :
user_pref("javascript.console.open_on_error", true);
is added to prefs.js when the console is automatically opened during JavaScript error.
4. Which of the following is possible to be referenced in external JavaScript?
a) cpp
b) cs
c) php
d) all of the mentioned
Answer
Answer: c [Reason:] One of the lesser known sides of external JavaScript is the ability to reference a PHP file instead of the familiar .js file.
5. Which of the following attribute takes the source of the PHP file?
a) img
b) src
c) source
d) none of the mentioned
Answer
Answer: b [Reason:] The syntax to referencing a PHP file using external JavaScript is consistent enough with what we already know:
<script type="text/javascript" src="myscript.php"></script>
6. What kind of path can the PHP file be?
a) Absolute
b) Relative
c) Either Absolute or Relative
d) Both Absolute and Relative
Answer
Answer: c [Reason:] The PHP file is either an absolute or relative path to a PHP script instead of the usual .js file.
7. Which of the following global variables is used to get parameters?
a) $HTTP_GET_VAR[].
b) $HTTP_GET_VARS()
c) $HTTP_GET_VARS
d) $HTTP_GET_VARS[].
Answer
Answer: d [Reason:] The global variable $HTTP_GET_VARS[] is used to get parameters.
8. What is the purpose of the RegExp method test()?
a) Tests for a match in its float parameter
b) Tests for a match in its string parameter
c) Tests for a match in its integer parameter
d) None of the mentioned
Answer
Answer: b [Reason:] The RegExp method test() tests for a match in its string parameter.
9. What is the purpose of the function parameter filetype?
a) File type to be expected
b) File type previously got
c) File type that should not be got
d) None of the mentioned
Answer
Answer: a [Reason:] The function parameter “filetype” lets you tell the script what file type to expect before loading.
10. Which of the following is the method used to add an element to the desired location?
a) add.element()
b) element.add()
c) element.appendChild()
d) none of the mentioned
Answer
Answer: c [Reason:] The method element.appendChild() is used to add the element to the desired location within the document tree.
Java MCQ Set 2
1. Firebug is an extension of which browser?
a) Mozilla
b) Chrome
c) IE
d) Opera
Answer
Answer: a [Reason:] Firebug is an extension of Mozilla.
2. Firebug can be used to inspect
a) HTML
b) CSS
c) DOM
d) All of the mentioned
Answer
Answer: d [Reason:] Firebug is an extension for the Mozilla Firefox browser that allows you to debug and inspect HTML, CSS, the Document Object Model (DOM) and JavaScript.
3. Why do Web Developers use Firebug?
a) Track cookies
b) Track sessions
c) Both Track cookies and sessions
d) None of the mentioned
Answer
Answer: c [Reason:] Web developers use Firebug for the following reasons :
- Inspect the behavior of HTML/CSS, and modify style & layout with true WYSIWYG
- Debug JavaScript
- Detect performance of website
- Track Cookies & Sessions
4. What are the goals for using Firebug?
a) Performance
b) Adaptability
c) Complexity
d) Reliability
Answer
Answer: a [Reason:] The goals for using Firebug is :
- Performance
- Modularity
- Shared code
- Compatibility
5. Which of the following is not a feature of the User Interface?
a) Skinnable Interface
b) Resizable Side Panel
c) Fixed Side Panel
d) Menu options
Answer
Answer: c [Reason:] The features present in the User Interface are :
- Port of Firebug’s Visual Object Representation (aka Reps)
- Recreation of Firebug 1.3 User Interface with pixel precision
- Menu options
- Resizable Side Panel
- Skinnable Interface
6. What is the default value of the property overrideConsole>
a) 1
b) true
c) 0
d) false
Answer
Answer: b [Reason:] The default value of the property overrideConsole is true.
7. Which of the following property(s) has a default value as false?
a) disableWhenFirebugActive
b) showIconWhenHidden
c) disableXHRListener
d) Both disableWhenFirebugActive & showIconWhenHidden
Answer
Answer: c [Reason:] Only disableXHRListener property has a default value false. The properties disableWhenFirebugActive and showIconWhenHidden has a default value of true.
8. Which of the following action is possible in Firebug when used as a JavaScript Debugger and Profiler?
a) Pause execution in any line
b) Find Scripts easily
c) Find Scripts easily & also Pause execution in any line
d) None of the mentioned
Answer
Answer: c [Reason:] When Firebug is used as a JavaScript Debugger and Profiler, it can be used to find scripts easily and also pause the execution in any desired line.
9. Consider the following code snippet
console.log(p)
If p is not defined, what would be the result or type of error?
a) Zero
b) Null
c) ReferenceError
d) ValueNotFoundError
Answer
Answer: c [Reason:] In the above code snippet, p is not defined) Hence, it gives a ReferenceError.
10. The let keyword can be used
a) in a for or for/in loop, as a substitute for var
b) as a block statement, to define new variables
c) to define variables that are scoped to a single expression
d) all of the mentioned
Answer
Answer: d [Reason:] The let keyword can be used in four ways :
- as a variable declaration like var;
- in a for or for/in loop, as a substitute for var;
- as a block statement, to define new variables and explicitly delimit their scope; and
- to define variables that are scoped to a single expression.
Java MCQ Set 3
1. What does an History object contain?
a) URL
b) Parameters
c) Attribute values
d) Property
Answer
Answer: a [Reason:] The history object contains the URLs visited by the user (within a browser window).
2. The history object is a part of which object?
a) Property
b) Window
c) Location
d) Screen
Answer
Answer: b [Reason:] The history object belongs to the Window object.
3. How many methods are there in the History object?
a) 3
b) 4
c) 5
d) 6
Answer
Answer: a [Reason:] There are three methods belongign to the History object namely :
- back()
- forward()
- go()
4. What is the purpose of the method forward()?
a) Loads any random URL in the history list
b) Loads the previous URL in the history list
c) Loads a specific URL from the history list
d) Loads the next URL in the history list
Answer
Answer: d [Reason:] The forward() method loads the next URL in the history list.
5. How will you update the URL displayed in the location bar?
a) location
b) location.URL
c) location.hash
d) url
Answer
Answer: c [Reason:] The property location.hash needs to be updated to display the updated URL in the location bar.
6. How do you add a particular state to the browsing history?
a) pushState()
b) replaceState()
c) state()
d) none of the mentioned
Answer
Answer: a [Reason:] The pushState() method adds a particular state to the browsing history.
7. What does the pushState() method do?
a) Removes the state
b) Adds new state
c) Replaces the state
d) None of the mentioned
Answer
Answer: b [Reason:] When a web app enters a new state, it calls history.pushState() to add that state to the browsing history.
8. Which of the following method is used to replace the current history state instead of adding a new state to the browsing history?
a) replaceState()
b) replace(state)
c) replace()
d) none of the mentioned
Answer
Answer: a [Reason:] The replaceState() method is used to replace the current history state instead of adding a new state to the browsing history.
9. How many parameters does the replaceState() method take?
a) 2
b) 3
c) 4
d) 5
Answer
Answer: b [Reason:] window.history.replaceState(stateObj, title, url) : This is just like window.history.pushState, except that the current browser state is removed from the history, so you cannot hit “back” to return to it.
10. What is the purpose of the event window.onpopstate?
a) When a state object is replaced
b) When a state object is added
c) When a state object is removed
d) None of the mentioned
Answer
Answer: c [Reason:] The window.onpopstate event is fired whenever a state object is removed from the browser history, which occurs on browser “back” or “forward”. State objects are persisted on the user’s hard disk between sessions, which is a nice feature. The object passed into a call to pushState or replaceState is provided as the state property on the event object in the “popstate” event.
Java MCQ Set 4
1. Where are memory leaks found?
a) Client side objects
b) Server side objects
c) Both Client side and Server side objects
d) None of the mentioned
Answer
Answer: a [Reason:] Memory leaks occur when we are developing client-side reusable scripting objects.
2. 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) none of the mentioned
Answer
Answer: a [Reason:] 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.
3. What is the central concept of JavaScript memory management?
a) Reliability
b) Reachability
c) Efficiency
d) Transparency
Answer
Answer: b [Reason:] The central concept of JavaScript memory management is a concept of reachability.
- A distinguished set of objects are assumed to be reachable: these are known as the roots. Typically, these include all the objects referenced from anywhere in the call stack (that is, all local variables and parameters in the functions currently being invoked), and any global variables.
- Objects are kept in memory while they are accessible from roots through a reference or a chain of references.
4. When does a memory leak happen?
a) Browser doesn’t release memory from objects unnecessary
b) Browser releases too many memories
c) All of the mentioned
d) None of the mentioned
Answer
Answer: a [Reason:] Memory leak happens when the browser for some reason doesn’t release memory from objects which are not needed any more.
5. What will happen when the data of the jQuery.cache is read from an element?
a) Unique number is retrieved as elem[jQuery.expando]
b) Data is read from jQuery.cache[id]
c) Unique number is retrieved as elem[jQuery.expando] & Data is read from jQuery.cache[id]
d) None of the mentioned
Answer
Answer: c [Reason:] When the data is read from an element:
- The element unique number is retrieved from id = elem[ jQuery.expando].
- The data is read from jQuery.cache[id].
6. The style property belongs to while of the following object?
a) Element
b) Window
c) Location
d) None of the mentioned
Answer
Answer: a [Reason:] 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.
7. Which of the following functions are referenced internally?
a) setTimeout
b) setInterval
c) both setTimeout and setInterval
d) none of the mentioned
Answer
Answer: c [Reason:] Functions used in setTimeout/setInterval are referenced internally and tracked until complete, then cleaned up.
8. What is the purpose of destroying the functions and objects?
a) Consume unnecessary CPU cycles
b) Prevent the dropping of reference count to 0
c) Centralize the responsibility to clean up
d) All of the mentioned
Answer
Answer: d [Reason:] The primary purpose of a destroy function is to centralize the responsibility for cleaning up anything that the object has done that will:
- Prevent its reference count from dropping to 0 (for example, removing problematic event listeners and callbacks and unregistering from any services).
- Consume unnecessary CPU cycles, such as intervals or animations.
9. When does a cycle occur during memory leak?
a) No reference occurs
b) Two objects reference
c) One object gets referenced
d) None of the mentioned
Answer
Answer: b [Reason:] A cycle happens when two objects reference each other in such a way that both objects retain each other.
10. Which of the following is a way to retain an object in memory?
a) Console Log
b) Closures
c) Destory objects
d) All of the mentioned
Answer
Answer: a [Reason:] One particularly obscure way to retain an object in memory is to log it to the console.
Java MCQ Set 5
1. Consider the following code snippet
function printArray(a) { var len = a.length, i = 0; if (len == 0) console.log("Empty Array"); else { do { console.log(a[i]); } while (++i < len); } }
What does the above code result?
a) Prints the numbers in the array in order
b) Prints the numbers in the array in the reverse order
c) Prints 0 to the length of the array
d) Prints “Empty Array”
Answer
Answer: a [Reason:] The do/while loop is less commonly used when compared to the while loop. Here, it prints from the array in the given order.
2. What are the three important manipulations done in a for loop on a loop variable?
a) Updation, Incrementation, Initialization
b) Initialization,Testing, Updation
c) Testing, Updation, Testing
d) Initialization,Testing, Incrementation
Answer
Answer: b [Reason:] In a for loop, the initialization, the test, and the update are the three crucial manipulations of a loop variable.
3. Consider the following code snippet
function tail(o) { for (; o.next; o = o.next) ; return o; }
Will the above code snippet work? If not, what will be the error?
a) No, this will throw an exception as only numerics can be used in a for loop
b) No, this will not iterate
c) Yes, this will work
d) No, this will result in a runtime error with the message “Cannot use Linked List”
Answer
Answer: c [Reason:] The above code uses a for loop to traverse a linked list data structure and return the last object in the list. This will perfectly work.
4. Consider the following code snippet
for(var p in o) console.log(o[p]);
The above code is equivalent to which code?
a) for (var i = 0;i < a.length;i++) console.log(a[i]); b) for (int i = 0;i < a.length;i++) console.log(a[i]); c) for (var i = 0;i <= a.length;i++) console.log(a[i]); d) for (var i = 1;i < a.length;i++) console.log(a[i]);
Answer
Answer: a [Reason:] The for/in loop makes it easy to do the same that we do using a for.
5. One of the special feature of an interpreter in reference with the for loop is that
a) Before each iteration, the interpreter evaluates the variable expression and assigns the name of the property
b) The iterations can be infinite when an interpreter is used
c) The body of the loop is executed only once
d) All of the mentioned
Answer
Answer: a [Reason:] Before each iteration, the interpreter evaluates the variable expression and assigns the name of the property (a string value) to it.
6. What will happen if the body of a for/in loop deletes a property that has not yet been enumerated?
a) The property will be stored in a cache
b) The loop will not run
c) That property will not be enumerated
d) All of the mentioned
Answer
Answer: c [Reason:] If the body of a for/in loop deletes a property that has not yet been enumerated, that property will not be enumerated. If the body of the loop defines new properties on the object, those properties will generally not be enumerated.
7. What will be the step of the interpreter in a jump statement when an exception is thrown?
a) The interpreter stops its work
b) The interpreter throws another exception
c) The interpreter jumps to the nearest enclosing exception handler
d) None of the mentioned
Answer
Answer: c [Reason:] When an exception is thrown in a jump statement, the interpreter jumps to the nearest enclosing exception handler, which may be in the same function or up the call stack in an invoking function.
8. Consider the following code snippet
while (a != 0) { if (a == 1) continue; else a++; }
What will be the role of the continue keyword in the above code snippet?
a) The continue keyword restarts the loop
b) The continue keyword skips the next iteration
c) The continue keyword skips the rest of the statements in that iteration
d) None of the mentioned
Answer
Answer: c [Reason:] Instead of exiting a loop like the break keyword, the continue keyword moves to the next iteration from the place encountered.
9. Consider the following code snippet
function f(o) { if (o === undefined) debugger; }
What could be the task of the statement debugger?
a) It does nothing but a simple breakpoint
b) It debugs the error in that statement and restarts the statement’s execution
c) It is used as a keyword that debugs the entire program at once
d) All of the mentioned
Answer
Answer: a [Reason:] The debugger statement normally does nothing. If, however, a debugger program is available and is running, then an implementation may (but is not required to) perform some kind of debugging action. In practice, this statement acts like a breakpoint: execution of JavaScript code stops and you can use the debugger to print variable’s values.
10. Among the keywords below, which one is not a statement?
a) debugger
b) with
c) if
d) use strict
Answer
Answer: d [Reason:] use strict is a directive introduced in ECMAScript5. Directives are not statements because it does not include any language keywords. Also, it can appear only at the start of a script or at the start of a function body, before any real statemenst have appeared.