Classes And Modules(Javascript ) Questions and Answers

Question 1. Which is the object that defines methods that allow complete control over page content?
  1.    The client-side document object
  2.    The server-side document object
  3.    Both client-side and server-side document object
  4.    None of the mentioned
Explanation:-
Answer: Option A. -> The client-side document object
The client-side document object defines methods that allow complete control over page content.

Question 2. Which is the subset that transforms web content into secure modules that can be safely hosted on a web page?
  1.    Microsoft Web Sandbox
  2.    ADsafe
  3.    Caja
  4.    dojox.secure
Explanation:-
Answer: Option D. -> dojox.secure
Caja is Google’s open-source secure subset. Caja (Spanish for “box”) defines two language subsets. Cajita (“little box”) is a narrow subset like that used by ADsafe and dojox.secure. Valija (“suitcase” or “baggage”) is a much broader language that is close to regular ECMAScript 5 strict mode (with the removal of eval()). Caja itself is the name of the compiler that transforms (or “cajoles”) web content (HTML, CSS, and JavaScript code) into secure modules that can be safely hosted on a web page without being able to affect the page as a whole or other modules on the page.

Question 3. Consider the following code snippet
const pi=3.14;
var pi=4;
console.log(pi);
What will be the output for the above code snippet?
  1.    This will flash an error
  2.    Prints 4
  3.    Prints 3.14
  4.    Ambiguity
Explanation:-
Answer: Option A. -> This will flash an error
The above code snippet will flash an error. Attempts to alter the value or re-declaration causes errors.

Question 4. The let keyword can be used
  1.    in a for or for/in loop, as a substitute for var
  2.    as a block statement, to define new variables
  3.    to define variables that are scoped to a single expression
  4.    all of the mentioned
Explanation:-
Answer: Option A. -> in a for or for/in loop, as a substitute for var
The let keyword can be used in four ways :
1. as a variable declaration like var;
2. in a for or for/in loop, as a substitute for var;
3. as a block statement, to define new variables and explicitly delimit their scope; and
4. to define variables that are scoped to a single expression.

Question 5. Which was one of the first security subsets proposed?
  1.    FBJS
  2.    Caja
  3.    dojox.secure
  4.    ADSafe
Explanation:-
Answer: Option D. -> ADSafe
ADsafe was one of the first security subsets proposed) It was created by Douglas Crockford (who also defined The Good Parts subset).ADsafe relies on static verification only, and it uses JSLint as its verifier. It forbids access to most global variables and defines an ADSAFE variable that provides access to a secure API, including special-purpose DOM methods. ADsafe is not in wide use, but it was an influential proof-of-concept that influenced other secure subsets.

Question 6. What is the code to be used to trim whitespaces ?
  1.    let trimmed = (l.trim() for (l in lines));
  2.    let trimmed = (trim(l));
  3.    let trimmed = l.trim();
  4.    let trimmed = for(l in lines));
Explanation:-
Answer: Option A. -> let trimmed = (l.trim() for (l in lines));
We can use the above code to trim whitespaces and filter out comments and blank lines.

Question 7. When will the finally block be called?
  1.    When there is no exception
  2.    When the catch doesnot match
  3.    When there is exception
  4.    None of the mentioned
Explanation:-
Answer: Option D. -> None of the mentioned
A finally block is called after try-catch execution.

Question 8. Which method to use while working with XML fragments, instead of XML()?
  1.    XMLInterface()
  2.    XMLClass()
  3.    XMLList()
  4.    XMLArray()
Explanation:-
Answer: Option C. -> XMLList()

Question 9. What will be the reaction when a catch clause has no conditionals ?
  1.    Takes it to be 0
  2.    Takes it to be 1
  3.    Takes it to be true
  4.    Takes it to be false
Explanation:-
Answer: Option C. -> Takes it to be true
If a catch clause has no conditional, it behaves as if it has the conditional if true, and it is always triggered if no clause before it was triggered.

Question 10. What is the return type of typeof for standard JavaScript objects?
  1.    xml
  2.    object
  3.    dom
  4.    html
Explanation:-
Answer: Option B. -> object
The typeof operator returns “object” for all standard JavaScript objects as functions are, and the typeof operator returns “xml”.