JavaScript Questions & Answers – JavaScript Subsets

«
»

This set of Javascript Multiple Choice Questions & Answers (MCQs) focuses on “JavaScript Subsets”.

1. The Crockford’s subset does not include which function in JavaScript?
a) eval()
b) coeval()
c) equal()
d) equivalent()
View Answer

Answer: a
Explanation: The Crockford’s subset does not include the with and continue statements or the eval() function. It defines functions using function definition expressions only and does not include the function definition statement.
advertisement

2. What does javascript use instead of == and !=?
a) It uses bitwise checking
b) It uses === and !== instead
c) It uses equals() and notequals() instead
d) It uses equalto()
View Answer

Answer: b
Explanation: The subset does not include the comma operator, the bitwise operators, or the ++ and — operators. It also disallows == and != because of the type conversion they perform, requiring use of === and !== instead.

3. What is being imposed on each subset to ensure that it conforms to the subset?
a) A parser to parse the code
b) A parser that parses and adds to the subset
c) A static verifier that parses code
d) A predefined function to parse the code
View Answer

Answer: c
Explanation: Each subset is coupled with a static verifier that parses code to ensure that it conforms to the subset.
Note: Join free Sanfoundry classes at Telegram or Youtube
advertisement
advertisement

4. Why was “The Good Parts” designed as a language subset in JavaScript?
a) To improve programmer flexibility
b) To balance the workload of the programmer
c) To create an in-built compiler and interpreter
d) To improve programmer productivity
View Answer

Answer: d
Explanation: The Good Parts is a language subset designed for aesthetic reasons and with a desire to improve programmer productivity. There is a larger class of subsets that have been designed for the purpose of safely running untrusted JavaScript in a secure container or “sandbox”.

5. Which is the subset that is a secure container designed for the purpose of safely running untrusted JavaScript?
a) Sandbox
b) The Good Parts
c) Both Sandbox and Good Parts
d) Web browser
View Answer

Answer: a
Explanation: There is a larger class of subsets that have been designed for the purpose of safely running untrusted JavaScript in a secure container or “sandbox”.
Take JavaScript Practice Tests - Chapterwise!
Start the Test Now: Chapter 1, 2, 3, 4, 5, 6, 7, 8, 9, 10
advertisement

6. Why is this keyword not preferred in JavaScript?
a) Highly memory consuming
b) Functions should access the global objects
c) Functions should not access the global objects
d) Very inefficient to use
View Answer

Answer: c
Explanation: The this keyword is forbidden or restricted because functions (in non-strict mode) can access the global object through this. Preventing access to the global object is one of the key purposes of any sandboxing system.

7. Which are the two functions that are not allowed in any secure subset?
a) evaluate() and restrict()
b) eval() and the Function() constructor
c) debugger() and test()
d) eval() and debugger()
View Answer

Answer: b
Explanation: eval() and the Function() constructor are not allowed in any secure subset because they allow the execution of arbitrary strings of code, and these strings cannot be statically analyzed.
advertisement

8. Which is the object that defines methods that allow complete control over page content?
a) The client-side document object
b) The server-side document object
c) Both client-side and server-side document object
d) Web document object
View Answer

Answer: a
Explanation: A web page is divided into two object documents in which one is client-side document object and the other is server-side document object. The client-side document object defines methods that allow complete control over page content

9. Which was one of the first security subsets proposed?
a) FBJS
b) Caja
c) dojox.secure
d) ADSafe
View Answer

Answer: d
Explanation: 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.
advertisement

10. Which is the subset that transforms web content into secure modules that can be safely hosted on a web page?
a) Microsoft Web Sandbox
b) ADsafe
c) Caja
d) dojox.secure
View Answer

Answer: d
Explanation: 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.

11. What will be the output of the following JavaScript code?

var set = new Set();  
set.add("one");  
set.add("two");    
for (let elements of set) 
{  
    document.writeln(elements+" ");  
}

a) one
b) two
c) one two
d) undefined
View Answer

Answer: c
Explanation: The JavaScript Set add() method is used to add an element to Set object with a specified value. Each element must have a unique value.

12. What will be the output of the following JavaScript code?

set.add("AngularJS");  
set.add("Bootstrap");    
set.delete("Bootstrap");  
document.writeln(set.size);

a) 2
b) 1
c) 0
d) Undefined
View Answer

Answer: b
Explanation: The delete() method is used to remove all the elements from the Set object which are passed as an argument to the delete function. Since the delete function is called once the size will be reduced to 1.

13. What will be the output of the following JavaScript code?

set.add("one");  
set.add("two");  
set.add("three");    
set.clear();  
document.writeln(set.size);

a) one
b) 1
c) 2
d) 0
View Answer

Answer: d
Explanation: JavaScript Set clear() method is used to remove all the elements from Set object. The clear method will remove all the entries and hence the size of the set will be zero.

14. What will be the output of the following JavaScript code?

set.add("one");  
set.add("two”);
var itr=set.values();  
document.writeln(itr.next().value);

a) one
b) two
c) error
d) undefined
View Answer

Answer: a
Explanation: values() method returns an object of new Set iterator. This object contains the value for each element. It maintains insertion order.

15. What will be the output of the following JavaScript code?

set.add("1");  
set.add("2");    
document.writeln(set.has("3"));

a) 3
b) true
c) false
d) 2
View Answer

Answer: c
Explanation: The Set has() method indicates whether the Set object contains the specified value. It returns true if the specified value is present, otherwise false.

Sanfoundry Global Education & Learning Series – Javascript Programming.

advertisement
advertisement
Subscribe to our Newsletters (Subject-wise). Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!

Youtube | Telegram | LinkedIn | Instagram | Facebook | Twitter | Pinterest
Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & technical discussions at Telegram SanfoundryClasses.