MCQs > IT & Programming > JavaScript MCQs > Basic JavaScript MCQs

Basic JavaScript MCQ

1. ____ cookies remain available only for the current browser session.

Answer

Correct Answer: Temporary

Note: This Question is unanswered, help us to find answer for this one

2. Through the use of the ____ plug-in, a webpage can provide a user with an interactive experience.

Answer

Correct Answer: Flash

Note: This Question is unanswered, help us to find answer for this one

3. The ________ loads java bytecode to the memory.

Answer

Correct Answer: Class loaderd

Note: This Question is unanswered, help us to find answer for this one

4. The ____ property of the location object contains a url?s query or search parameters.

Answer

Correct Answer: Search

Note: This Question is unanswered, help us to find answer for this one

5. A(n) ____ comment hides multiple lines of code.

Answer

Correct Answer: Block

Note: This Question is unanswered, help us to find answer for this one

6. A plug-in either opens in its own external window or runs within a web page as a(n) _____.

Answer

Correct Answer: Embedded object

Note: This Question is unanswered, help us to find answer for this one

7. A pattern that matches the beginning or end of a line is called a(n) ____.

Answer

Correct Answer: Anchor

Note: This Question is unanswered, help us to find answer for this one

8. When using the console.log() method to trace bugs, it can be helpful to use a ____ program.

Answer

Correct Answer: Driver

Note: This Question is unanswered, help us to find answer for this one

9. In the google maps api, the ____ constructor creates a map object.

Answer

Correct Answer: Map()

Note: This Question is unanswered, help us to find answer for this one

10. If nothing within a while loop ever causes the condition to become false, a(n) ________ may occur.

Answer

Correct Answer: Infinite loop

Note: This Question is unanswered, help us to find answer for this one

11. What will this code log to the console?

Answer

Correct Answer: Number

Note: This Question is unanswered, help us to find answer for this one

12. What will be logged to the console? console.log(typeof 'blueberry');

Answer

Correct Answer: String

Note: This Question is unanswered, help us to find answer for this one

13. Which JavaScript loop ensures that at least a singular iteration will happen?

Answer

Correct Answer: Do…while

Note: This Question is unanswered, help us to find answer for this one

14. Which method call is chained to handle a successful response returned by fetch()?

Answer

Correct Answer: Then()

Note: This Question is unanswered, help us to find answer for this one

15. Which statement correctly imports this code from some-file.js? //some-file.js Export const printMe = (str) => console.log(str);

Answer

Correct Answer: Import { printMe } from './some-file';

Note: This Question is unanswered, help us to find answer for this one

16. Which statement can take a single expression as input and then look through a number of choices until one that matches that value is found?

Answer

Correct Answer: Switch

Note: This Question is unanswered, help us to find answer for this one

17. What is the difference between the map() and the forEach() methods on the Array prototype?

Answer

Correct Answer: The map() methods returns a new array with a transformation applied on each item in the original array, whereas the forEach() method iterates through an array with no return value.

Note: This Question is unanswered, help us to find answer for this one

18. How do you remove the property name from this object? const foo = { name: 'Albert', };

Answer

Correct Answer: Delete foo.name;

Note: This Question is unanswered, help us to find answer for this one

19. Which class-based lifecycle method would be called at the same time as this effect Hook? useEffect(() => { // do things }, []);

Answer

Correct Answer: ComponentDidMount

Note: This Question is unanswered, help us to find answer for this one

20. Which event is fired on a text field within a form when a user tabs to it, or clicks or touches it?

Answer

Correct Answer: Focus

Note: This Question is unanswered, help us to find answer for this one

21. What is the HTTP verb to request the contents of an existing resource?

Answer

Correct Answer: GET

Note: This Question is unanswered, help us to find answer for this one

22. Why would you choose an asynchronous structure for your code?

Answer

Correct Answer: To start tasks that might take some time without blocking subsequent tasks from executing immediately

Note: This Question is unanswered, help us to find answer for this one

23. Which statement selects all img elements in the DOM tree?

Answer

Correct Answer: Document.querySelectorAll('img')

Note: This Question is unanswered, help us to find answer for this one

24. Which statement represents the starting code converted to an IIFE?

Answer

Correct Answer: (function() { console.log('lorem ipsum'); })();

Note: This Question is unanswered, help us to find answer for this one

25. What is the result of running the statement shown? Let a = 5; Console.log(++a);

Answer

Correct Answer: 6

Note: This Question is unanswered, help us to find answer for this one

26. Which method is called automatically when an object is initialized?

Answer

Correct Answer: Constructor()

Note: This Question is unanswered, help us to find answer for this one

27. If you attempt to call a value as a function but the value is not a function, what kind of error would you get?

Answer

Correct Answer: TypeError

Note: This Question is unanswered, help us to find answer for this one

28. How do you add a comment to JavaScript code?

Answer

Correct Answer: // This is a comment

Note: This Question is unanswered, help us to find answer for this one

29. Which concept is defined as a template that can be used to generate different objects that share some shape and/or behavior?

Answer

Correct Answer: Class

Note: This Question is unanswered, help us to find answer for this one

30. Which choice is valid example for an arrow function?

Answer

Correct Answer: (a,b) => c

Note: This Question is unanswered, help us to find answer for this one

31. Which statement is used to skip iteration of the loop?

Answer

Correct Answer: Continue

Note: This Question is unanswered, help us to find answer for this one

32. Which method do you use to attach one DOM node to another?

Answer

Correct Answer: AppendChild()

Note: This Question is unanswered, help us to find answer for this one

33. Which method cancels event default behavior?

Answer

Correct Answer: PreventDefault()

Note: This Question is unanswered, help us to find answer for this one

34. Which of these is a valid variable name?

Answer

Correct Answer: FirstName

Note: This Question is unanswered, help us to find answer for this one

35. Which expression evaluates to true?

Answer

Correct Answer: 3 == '3'

Note: This Question is unanswered, help us to find answer for this one

36. Why might you choose to make your code asynchronous?

Answer

Correct Answer: To start tasks that might take some time without blocking subsequent tasks from executing immediately

Note: This Question is unanswered, help us to find answer for this one

37. Which choice is an incorrect way to define an arrow function that returns an empty object?

Answer

Correct Answer: => {}

Note: This Question is unanswered, help us to find answer for this one

38. How does the forEach() method differ from a for statement?

Answer

Correct Answer: ForEach can be used only with an array, whereas for can be used with additional data types.

Note: This Question is unanswered, help us to find answer for this one

39. Which collection object allows unique value to be inserted only once?

Answer

Correct Answer: Set

Note: This Question is unanswered, help us to find answer for this one

40. Which statement references the DOM node created by the code shown?

lorem ipsum

Answer

Correct Answer: Document.querySelector('.pull');

Note: This Question is unanswered, help us to find answer for this one

41. The following program has a problem. What is it? var a; var b = (a = 3) ? true : false;

Answer

Correct Answer: The condition in the ternary is using the assignment operator.

Note: This Question is unanswered, help us to find answer for this one

42. What's one difference between the async and defer attributes of the HTML script tag?

Answer

Correct Answer: The defer attribute will asynchronously load the scripts in order

Note: This Question is unanswered, help us to find answer for this one

43. Which keyword is used to create an error?

Answer

Correct Answer: Throw

Note: This Question is unanswered, help us to find answer for this one

44. What will the value of y be in this code: const x = 6 % 2; const y = x ? 'One' : 'Two';

Answer

Correct Answer: Two

Note: This Question is unanswered, help us to find answer for this one

45. How many prototype objects are in the chain for the following array? let arr = [];

Answer

Correct Answer: 2

Note: This Question is unanswered, help us to find answer for this one

46. Your code is producing the error: TypeError: Cannot read property 'reduce' of undefined. What does that mean?

Answer

Correct Answer: You are calling a method named reduce on an object that's declared but has no value.

Note: This Question is unanswered, help us to find answer for this one

47. Which statement is true about Functional Programming?

Answer

Correct Answer: Side effects are not allowed.

Note: This Question is unanswered, help us to find answer for this one

48. What type of function can have its execution suspended and then resumed at a later point?

Answer

Correct Answer: Generator function

Note: This Question is unanswered, help us to find answer for this one

49. What does the following expression evaluate to? [] == [];

Answer

Correct Answer: False

Note: This Question is unanswered, help us to find answer for this one

50. Which statement is true about the "async" attribute for the HTML script tag?

Answer

Correct Answer: It can be used only for external JavaScript code.

Note: This Question is unanswered, help us to find answer for this one

51. Why is it usually better to work with Objects instead of Arrays to store a collection of records?

Answer

Correct Answer: Most operations involve looking up a record, and objects can do that better than arrays.

Note: This Question is unanswered, help us to find answer for this one

52. Which variable is an implicit parameter for every function in JavaScript?

Answer

Correct Answer: Arguments

Note: This Question is unanswered, help us to find answer for this one

53. Which of the following is not a keyword in JavaScript?

Answer

Correct Answer: Array

Note: This Question is unanswered, help us to find answer for this one

54. Which of the following values is not a Boolean false?

Answer

Correct Answer: Boolean("false")

Note: This Question is unanswered, help us to find answer for this one

55. Which Variable-defining keyword allows its variable to be accessed (as undefined) before the line that defines it?

Answer

Correct Answer: Var

Note: This Question is unanswered, help us to find answer for this one

56. Why would you include a "use strict" statement in a JavaScript file?

Answer

Correct Answer: To tell parsers to enforce all JavaScript syntax rules when processing your code

Note: This Question is unanswered, help us to find answer for this one

57. Which statement sets the Person constructor as the parent of the Student constructor in the prototype chain?

Answer

Correct Answer: Student.prototype = new Person();

Note: This Question is unanswered, help us to find answer for this one

58. Which of the following operators can be used to do a short-circuit evaluation?

Answer

Correct Answer: \|\|

Note: This Question is unanswered, help us to find answer for this one

59. 0 && hi

Answer

Correct Answer: 0

Note: This Question is unanswered, help us to find answer for this one

60. What is one difference between collections created with Map and collections created with Object?

Answer

Correct Answer: You can count the records in a Map with a single method call.

Note: This Question is unanswered, help us to find answer for this one

61. Which Object method returns an iterable that can be used to iterate over the properties of an object?

Answer

Correct Answer: Object.keys()

Note: This Question is unanswered, help us to find answer for this one

62. When would you use a conditional statement?

Answer

Correct Answer: When you want your code to choose between multiple options.

Note: This Question is unanswered, help us to find answer for this one

63. Which method converts JSON data to a JavaScript object?

Answer

Correct Answer: JSON.parse()

Note: This Question is unanswered, help us to find answer for this one

64. Which property references the DOM object that dispatched an event?

Answer

Correct Answer: Target

Note: This Question is unanswered, help us to find answer for this one

65. How would you reference the text 'avenue' in the code shown? Let roadTypes = ['street', 'road', 'avenue', 'circle'];

Answer

Correct Answer: RoadTypes[2]

Note: This Question is unanswered, help us to find answer for this one

66. You need to match a time value such as 12:00:32. Which of the following regular expressions would work for your code?

Answer

Correct Answer: /\d\d:\d\d:\d\d/

Note: This Question is unanswered, help us to find answer for this one

67. How does a function create a closure?

Answer

Correct Answer: It returns a reference to a variable in its parent scope.

Note: This Question is unanswered, help us to find answer for this one

68. Which statement creates a new object using the Person constructor? Which statement creates a new Person object called "student"?

Answer

Correct Answer: Var student = new Person();

Note: This Question is unanswered, help us to find answer for this one

69. How is a forEach statement different from a for statement?

Answer

Correct Answer: A for statement is generic, but a forEach statement can be used only with an array.

Note: This Question is unanswered, help us to find answer for this one

70. Which operator returns true if the two compared values are not equal?

Answer

Correct Answer: !==

Note: This Question is unanswered, help us to find answer for this one

71. ________ is a standard for exchanging structured information over the web.

Answer

Correct Answer: Extensible Markup Language

Note: This Question is unanswered, help us to find answer for this one

72. Web pages are seen within a window called the _____.

Answer

Correct Answer: Viewport

Note: This Question is unanswered, help us to find answer for this one

73. The _______ defines every object and element on a web page.

Answer

Correct Answer: Document Object Model

Note: This Question is unanswered, help us to find answer for this one

74. The cookie property is created with a required ____ attribute.

Answer

Correct Answer: Name

Note: This Question is unanswered, help us to find answer for this one

75. When javascript displays a numeric value, it stores that value to ____ digits of accuracy.

Answer

Correct Answer: 16

Note: This Question is unanswered, help us to find answer for this one

76. You can break up a long statement into multiple lines as long as you don't break up a ________.

Answer

Correct Answer: All of the above

Note: This Question is unanswered, help us to find answer for this one

77. The ____ method repeatedly executes the same code after being called only once.

Answer

Correct Answer: ClearInterval().

Note: This Question is unanswered, help us to find answer for this one

78. The ____ metacharacter is used to allow a string to contain an alternate set of substrings.

Answer

Correct Answer: (|)

Note: This Question is unanswered, help us to find answer for this one

79. A(n) ____ is an object that has been created from an existing class.

Answer

Correct Answer: Instance

Note: This Question is unanswered, help us to find answer for this one

80. Value is a function of ___________ and ___________?

Answer

Correct Answer: Perceived benefits, perceived price

Note: This Question is unanswered, help us to find answer for this one

81. To manipulate arrays in your scripts, you use the methods and length property of the ____ class.

Answer

Correct Answer: Array

Note: This Question is unanswered, help us to find answer for this one

82. Many programming languages include a string operation called __________.

Answer

Correct Answer: Concatenation

Note: This Question is unanswered, help us to find answer for this one

83. In the bubble sort algorithm, the two arguments sent into the swap module are ________.

Answer

Correct Answer: None of the above

Note: This Question is unanswered, help us to find answer for this one

84. A function includes its ____, which are values used by the function.

Answer

Correct Answer: Parameters

Note: This Question is unanswered, help us to find answer for this one

85. Less than (<), greater than (>), and not (not equal to) are examples of ____.

Answer

Correct Answer: Comparison operators

Note: This Question is unanswered, help us to find answer for this one

86. The ________ operator is a unary operator, as it works with only one operand.

Answer

Correct Answer: NOT

Note: This Question is unanswered, help us to find answer for this one

87. If the expression is false, the ________ operator will return true.

Answer

Correct Answer: NOT

Note: This Question is unanswered, help us to find answer for this one

88. Use the ________ method to write text to a web page.

Answer

Correct Answer: Document.write()

Note: This Question is unanswered, help us to find answer for this one

89. To convert a javascript object to a json string, you use the ____ method.

Answer

Correct Answer: Stringify()

Note: This Question is unanswered, help us to find answer for this one

90. The ____ operator executes one of two expressions based on the results of a conditional expression.

Answer

Correct Answer: Conditional

Note: This Question is unanswered, help us to find answer for this one

91. The ____ method is used in javascript to execute code after a specific amount of time has elapsed.

Answer

Correct Answer: SetTimeout()

Note: This Question is unanswered, help us to find answer for this one

92. Function statements are contained within the function ____.

Answer

Correct Answer: Braces

Note: This Question is unanswered, help us to find answer for this one

93. A(n) ____ statement is used to end the execution of a switch statement.

Answer

Correct Answer: Break

Note: This Question is unanswered, help us to find answer for this one

94. A(n) ____ is a variable that is used within a function.

Answer

Correct Answer: Arameter

Note: This Question is unanswered, help us to find answer for this one

95. Javascript requires _____ programming knowledge and experience as java.

Answer

Correct Answer: The same

Note: This Question is unanswered, help us to find answer for this one

96. Methods that set values are called ____ methods.

Answer

Correct Answer: Mutator

Note: This Question is unanswered, help us to find answer for this one

97. The ____ function converts all of the letters in a string to capital letters.

Answer

Correct Answer: Strtoupper()

Note: This Question is unanswered, help us to find answer for this one

98. Each repetition of a looping statement is called a(n) ____.

Answer

Correct Answer: Iteration

Note: This Question is unanswered, help us to find answer for this one

99. After you throw an error, you use a ____ statement to handle the error.

Answer

Correct Answer: Catch

Note: This Question is unanswered, help us to find answer for this one

100. The ____ object is used to obtain information about the current web browser.

Answer

Correct Answer: Navigator

Note: This Question is unanswered, help us to find answer for this one

101. The ____ object contains methods and properties for working with regular expressions in javascript.

Answer

Correct Answer: RegExp

Note: This Question is unanswered, help us to find answer for this one

102. The ____ object allows you to change to a new web page from within javascript code.

Answer

Correct Answer: Location

Note: This Question is unanswered, help us to find answer for this one

103. The ____ method is used to clear a setinterval() method call.

Answer

Correct Answer: ClearInterval()

Note: This Question is unanswered, help us to find answer for this one

104. The ____ method is used to cancel a settimeout() method before its code executes.

Answer

Correct Answer: ClearTimeout

Note: This Question is unanswered, help us to find answer for this one

105. The ____ method constructs a text string from unicode character codes that are passed as arguments.

Answer

Correct Answer: FromCharCode()

Note: This Question is unanswered, help us to find answer for this one

106. The ____ attribute is used for sharing cookies across multiple servers in the same domain.

Answer

Correct Answer: Domain

Note: This Question is unanswered, help us to find answer for this one

107. You use the ____ method of the string class to split a string into an indexed array.

Answer

Correct Answer: Split()

Note: This Question is unanswered, help us to find answer for this one

108. You use a ____ statement within a try block to specify an error message.

Answer

Correct Answer: Throw

Note: This Question is unanswered, help us to find answer for this one

109. You can use the compound ____ to combine two strings.

Answer

Correct Answer: Assignment operator

Note: This Question is unanswered, help us to find answer for this one

110. Writing values directly to the console is known as ____.

Answer

Correct Answer: Logging

Note: This Question is unanswered, help us to find answer for this one

111. To check if an option button is selected, you access the value of its ____ property.

Answer

Correct Answer: Checked

Note: This Question is unanswered, help us to find answer for this one

112. To register a source for an action event with a handler, use ________.

Answer

Correct Answer: Source.setOnAction(handler)

Note: This Question is unanswered, help us to find answer for this one

113. To place a node in the left of a borderpane p, use ________.

Answer

Correct Answer: P.setLeft(node);

Note: This Question is unanswered, help us to find answer for this one

114. The type attribute value for javascript is ____.

Answer

Correct Answer: Text/javascript

Note: This Question is unanswered, help us to find answer for this one

115. The switch statement case value can evaluate to all of the following except ____.

Answer

Correct Answer: Double

Note: This Question is unanswered, help us to find answer for this one

116. The static method ________ of class string returns a formatted string.

Answer

Correct Answer: Format.

Note: This Question is unanswered, help us to find answer for this one

117. Regular expression patterns consist of literal characters and ____.

Answer

Correct Answer: Metacharacters

Note: This Question is unanswered, help us to find answer for this one

118. Parseint is a method in the _______ class.

Answer

Correct Answer: Integer

Note: This Question is unanswered, help us to find answer for this one

119. Objects are also called ____.

Answer

Correct Answer: Components

Note: This Question is unanswered, help us to find answer for this one

120. In order to make a window the active window, you use the ____ method of the window object.

Answer

Correct Answer: Focus()

Note: This Question is unanswered, help us to find answer for this one

121. For javascript external files the mime type is ____

Answer

Correct Answer: Text/javascript

Note: This Question is unanswered, help us to find answer for this one

122. Each piece of data contained in an array is called a(n) ____.

Answer

Correct Answer: Element

Note: This Question is unanswered, help us to find answer for this one

123. An infinite loop is an example of a(n) ____ error.

Answer

Correct Answer: Logic

Note: This Question is unanswered, help us to find answer for this one

124. A set of statements contained within a set of braces is known as a(n) ____ block.

Answer

Correct Answer: Command

Note: This Question is unanswered, help us to find answer for this one

125. A ________ is a reusable block of javascript statements.

Answer

Correct Answer: Function

Note: This Question is unanswered, help us to find answer for this one

126.

Which file will be displayed if a computer has all required codecs?

Video!


Answer

Correct Answer:

Video playback



Note: This Question is unanswered, help us to find answer for this one

127. Which of the following is true for Creational design patterns?

Answer

Correct Answer: Creational design patterns deal with various mechanisms of object creation

Note: This Question is unanswered, help us to find answer for this one

128.

What is the value of "n1" and "n2" after executing the following code?


var str = "Finding foo in Foo and Bar";

var nl = str.search("Foo");

var n2 = str.search(/Foo/i);


Answer

Correct Answer:

nl = 15, n2 = 8


Note: This Question is unanswered, help us to find answer for this one

129. What options are types of declarations in JavaScript?

Answer

Correct Answer: var: Declares a variable
let: Declares a block scope local variable
const: Declares a read-only named constant

Note: This question has more than 1 correct answers

Note: This Question is unanswered, help us to find answer for this one

130.

What is the result for the following code snippet?

function checkFun() {

console.log(res);

let res = 5000;

}