JavaScript is an interpreted programming language that is lightweight. JavaScript can be integrated with HTML and it makes it very easy to use. It is an open-source and cross-platform programming language. JavaScript is not the compiler, it is translated. JavaScript translator (which is already embedded in web browsers) is responsible for the translation.
Question 1: Which attribute should be used if we want to specify that script must be executed after the page has finished parsing?
A) defer
B) async
C) parse
D) None of these
Answer: defer
Explanation: defer is a boolean attribute that is specified when we want the script to be executed after the page has finished parsing.
Question 2: Which of the following can be used for calling JavaScript Code?
A) Triggering Event
B) Function/Method
C) Both of these
D) None of these
Answer: Function/Method
Explanation: By making function calls to a particular element, JavaScript code can be called. Another way is to call JavaScript Code is by using methods like onLoad, onClick, etc.
Question 3: External JavaScript code can be included inside an HTML document using which of the following attribute?
A) script
B) src
C) link
D) None of these
Answer: src
Explanation: The script tag is used for including JavaScipt code. In order to include external JavaScript files, the src attribute is used inside the script tag.
Question 4: Which of the following is not an error in JavaScript?
A) Division by zero
B) Missing brackets
C) Syntax Error
D) All of these
Answer: Division by zero
Explanation: Division by zero is not an error in JavaScript, infinity or negative infinity is returned. There is a special case, Zero divided by Zero in this case a special value called Not a Value is returned (also known as NaN).
Question 5: Which of the following can be used to check whether two objects have the same prototype or not?
A) == operator
B) === operator
C) equals() method
D) isPrototypeOf() method
Answer: isPrototypeOf() method
Explanation: isPrototypeOf() method can be used to check whether two objects have the same prototype or not.
Question 6: Which of the following would happen when the pop() method is called on an array?
A) Total length would be incremented by 1
B) Total length would be decremented by 1
C) Prints last element
D) None of these
Answer: Total length would be decremented by 1
Explanation: pop() method deletes the last element from the array hence decreasing/decrementing the size of the array by 1.
Question 7: pop() method deletes the last element from the array hence decreasing/decrementing the size of the array by 1.
Answer: pop() method deletes the last element from the array hence decreasing/decrementing the size of the array by 1.
Explanation: pop() method deletes the last element from the array hence decreasing/decrementing the size of the array by 1.
Question 8: Which of the following operators can be used in order to test if a particular property exists or not?
A) exists
B) in
C) present
D) None of these
Answer: in
Explanation: in operators can be used in order to test if a particular property exists or not. It is mostly used in looping statements for traversing arrays and objects.
Question 9: Which of the following is a function with no return type?
A) method
B) procedure
C) static function
D) None of these
Answer: procedure
Explanation: Void functions do not return any value. Functions that do not return any value are also known as procedures.
Question 10: Which of the following is not an example of closure?
A) Function
B) Object
C) Variable
D) None of these
Answer: None of these
Explanation: Closure can be defined as a function that has access to the parent scope even after the parent function is closed.