




























































































Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!





























































































Question 1. What is the primary way to create a new object using literal notation in JavaScript? A) new Object() B) {} C) Object.create() D) Object.new() Answer: B Explanation: {} is the literal notation used to create a new object in JavaScript quickly and easily. Question 2. How can you add a new property 'age' with value 30 to an existing object 'person'? A) person.addProperty('age', 30)
B) person['age'] = 30 C) person.set('age', 30) D) person.property('age', 30) Answer: B Explanation: Using bracket notation, you assign a value to a property dynamically or directly. Question 3. Which operator is used to check if an object has a specific property directly (not inherited)? A) in B) hasOwnProperty() C) exists() D) property()
Question 5. How does the '==' operator compare objects in JavaScript? A) Checks deep equality B) Checks reference identity C) Converts objects to strings and compares D) Always returns false for objects Answer: B Explanation: '==' compares object references, not their content; objects are equal only if they reference the same object. Question 6. Which method creates a shallow copy of an object? A) Object.clone() B) Object.assign()
C) Object.deepCopy() D) Object.copy() Answer: B Explanation: Object.assign() copies properties from source to target object, creating a shallow clone. Question 7. What does the spread operator (...) do when used with objects? A) Deep clones the object B) Creates a shallow copy of the object C) Merges objects into a string D) Converts object to array Answer: B
Question 9. Which method is used to define a property with specific attributes, such as writable or configurable? A) Object.defineProperty() B) Object.setProperty() C) Object.property() D) Object.create() Answer: A Explanation: Object.defineProperty() allows detailed configuration of object properties. Question 10. What does Object.preventExtensions() do to an object? A) Prevents adding new properties B) Makes all properties non-writable
C) Freezes the object completely D) Seals the object Answer: A Explanation: preventExtensions() prevents adding new properties but allows modification or deletion of existing ones. Question 11. How do you declare a class in JavaScript? A) function MyClass() { ... } B) class MyClass { ... } C) new class MyClass { ... } D) define MyClass { ... } Answer: B
Question 13. How do you create an instance of a class named 'Car'? A) new Car() B) Car() C) create Car() D) instantiate Car() Answer: A Explanation: Using new with the class name calls the constructor to create a new object. Question 14. How can a subclass inherit from a parent class in JavaScript? A) extends keyword B) inherits keyword
C) prototype Chain D) subclass keyword Answer: A Explanation: The extends keyword is used for inheritance between classes. Question 15. What is the purpose of the super keyword inside a subclass constructor? A) To call the parent class constructor B) To define a new property C) To override methods D) To indicate static context Answer: A
A) They are called on the class, not instances B) They are inherited automatically C) They are private D) They cannot have parameters Answer: A Explanation: Static methods are called directly on the class, not on individual objects. Question 18. What is the core idea behind prototypes in JavaScript? A) Objects are linked via a prototype chain for inheritance B) Each object has a class C) Objects are created from classes only
D) Prototype is used only for built-in objects Answer: A Explanation: JavaScript objects inherit properties through a prototype chain. Question 19. Which built-in object provides number-related constants and functions? A) Math B) Number C) MathObject D) NumberUtil Answer: B
A) Math.round() B) Math.floor() C) Math.ceil() D) Math.trunc() Answer: B Explanation: Math.floor() rounds down towards negative infinity. Question 22. How do you generate a random number between 0 (inclusive) and 1 (exclusive)? A) Math.random() B) Math.randomNumber() C) Math.randomInt()
D) Math.random(0,1) Answer: A Explanation: Math.random() returns a floating-point number in [0,1). Question 23. Which method is used to convert a string to uppercase? A) toUpperCase() B) toLowerCase() C) toLocaleUpperCase() D) convertToUpper() Answer: A Explanation: toUpperCase() converts all characters in a string to uppercase.
B) search() C) find() D) locate() Answer: A Explanation: indexOf() returns the index of the first occurrence of a specified substring. Question 26. How can you trim whitespace from both ends of a string in JavaScript? A) trim() B) strip() C) removeSpaces() D) clean()
Answer: A Explanation: trim() removes whitespace from both ends of a string. Question 27. How do you create a new Date object representing the current date and time? A) new Date() B) Date.now() C) Date() D) new Date.now() Answer: A Explanation: new Date() creates a date object for the current moment.