Which is a statement terminator in javascript mcq

Home » MCQs

JavaScript, often abbreviated JS, is a programming language that is one of the core technologies of the World Wide Web, alongside HTML and CSS.

JavaScript MCQs: This section contains JavaScript Multiple-Choice Questions with Answers. These JavaScript MCQs are written for beginners as well as advanced, practice these MCQs to enhance and test the knowledge of JavaScript.

List of JavaScript MCQs

1. JavaScript is the programming language of the _____.

  1. Desktop
  2. Mobile
  3. Web
  4. Server

Answer: C] Web

Explanation:

JavaScript is the programming language of the Web.

Discuss this Question

2. Which type of JavaScript language is _____?

  1. Object-oriented
  2. Object-based
  3. Functional programming
  4. All of the above

Answer: B] Object-based

Explanation:

JavaScript is an object-oriented based programming language.

Discuss this Question

3. Which of the following statement[s] is true about the JavaScript?

  1. It is a scripting language used to make the website interactive
  2. It is an advanced version of Java for Desktop and Mobile application development
  3. It is a markup language of Java to develop the webpages
  4. All of the above

Answer: A] It is a scripting language used to make the website interactive

Explanation:

The correct statement about the JavaScript programming language is "It is a scripting language used to make the website interactive".

Discuss this Question

4. In which HTML element, we put the JavaScript code?

  1. ...
  2. ...
  3. ...
  4. ...

Answer: C] ...

Explanation:

The JavaScript code is written inside the ... tag/element.

Discuss this Question

5. JavaScript code can be written in ____.

  1. JavaScript file [.js file]
  2. HTML document directly
  3. JavaScript file and in HTML document directly
  4. In style sheets [.css file]

Answer: C] JavaScript file and in HTML document directly

Explanation:

JavaScript code can be written in the JavaScript file and in HTML document directly.

Discuss this Question

6. Which symbol is used separate JavaScript statements?

  1. Comma [,]
  2. Colon [:]
  3. Hyphen [_]
  4. Semicolon [;]

Answer: D] Semicolon [;]

Explanation:

The semicolon [;] is used to separate the JavaScript statements.

Discuss this Question

7. JavaScript ignores?

  1. newlines
  2. tabs
  3. spaces
  4. All of the above

Answer: D] All of the above

Explanation:

JavaScript ignores spaces, tabs, and newlines written in the code, we can use them for the alignment and separate the sections to give a perfect look at our code.

Discuss this Question

8. Which is the correct syntax to call an external JavaScript file in the current HTML document?

Answer: A]

Explanation:

The correct syntax to call an external JavaScript file in the current HTML document is:

Discuss this Question

9. Which JavaScript method is used to access an HTML element by id?

  1. getElementById[]
  2. getElement[id]
  3. getElementById[id]
  4. elementById[id]

Answer: C] getElementById[id]

Explanation:

The JavaScript method document.getElementById[id] is used to access an HTML document by id.

Discuss this Question

10. Which property is used to define the HTML content to an HTML element with a specific id?

  1. innerText
  2. innerContent
  3. elementText
  4. innerHTML

Answer: D] innerHTML

Explanation:

The innerHTML is the property that defined HTML content.

Example:

document.getElementById["notif"].innerHTML = "New course launched";

Discuss this Question

11. Which JavaScript method is used to write HTML output?

  1. document.write[]
  2. document.output[]
  3. console.log[]
  4. document.writeHTML[]

Answer: A] document.write[]

Explanation:

The JavaScript method document.write[] defines the HTML output.

Discuss this Question

12. Which JavaScript method is used to write on browser's console?

  1. console.write[]
  2. console.output[]
  3. console.log[]
  4. console.writeHTML[]

Answer: C] console.log[]

Explanation:

The JavaScript method console.log[] is used to write on browser's console.

Discuss this Question

13. Which JavaScript method is used to write into an alert box?

  1. window.alertHTML[]
  2. window.alert[]
  3. window.alertBox[]
  4. window.alertContent[]

Answer: B] window.alert[]

Explanation:

The JavaScript method window.alert[] is used to write into an alert box.

Discuss this Question

14. Which is the correct JavaScript statement to display "Hello Boss!" into an alert box?

  1. alert["Hello Boss!"];
  2. alert['Hello Boss!'];
  3. alert[Text:'Hello Boss!'];
  4. Both A. and B.

Answer: D] Both A. and B.

Explanation:

The both of statement are correct to display "Hello Boss!" into an alert box:

window.alert["Hello Boss!"];
window.alert['Hello Boss!'];

Discuss this Question

15. Which is the correct JavaScript statement to print the addition of two numbers 10 and 20 in a paragraph whose id is 'result'?

  1. getElementById["result"].innerHTML = 10+20;
  2. getElementById["result"].innerHTML = "10+20";
  3. getElementById["#result"].innerHTML = 10+20;
  4. All of the above

Answer: A] getElementById["result"].innerHTML = 10+20;

Explanation:

The correct JavaScript statement to print the addition of two numbers 10 and 2o in a paragraph whose id is "result" is:

document.getElementById["result"].innerHTML = 10+20;

Discuss this Question

16. What is the use of this JavaScript statement?

Submit
  1. It will write "Submit" on the current Window
  2. It will print the content of the current page
  3. It will write the content of the current page in the browser’s console
  4. None of the above

Answer: B] It will print the content of the current page

Explanation:

The window.print[] method prints the content of the current page.

Discuss this Question

17. In JavaScript, single line comment begins with ___.

  1. #
  2. /*
  3. $
  4. //

Answer: D] //

Explanation:

In JavaScript, single line comment begins with //.

Discuss this Question

18. In JavaScript, multi-line comments start with __ and end with ___.

  1. /* and */
  2. ## and ##
  3. // and //

Answer: A] /* and */

Explanation:

In JavaScript, multi-line comments start with /* and end with */.

Discuss this Question

19. Which JavaScript keyword is used to declare a variable?

  1. Var
  2. var
  3. Let
  4. All of the above

Answer: B] var

Explanation:

The var keyword defines a variable in JavaScript.

Discuss this Question

20. How many keywords are there in JavaScript to declare variables or constants?

  1. 1
  2. 2
  3. 3
  4. 4

Answer: C] 3

Explanation:

There are 3 ways / keywords to declare variables or constants, those are:

  • var
  • let
  • const

Discuss this Question

21. What is the main difference between var and let keywords in JavaScript?

  1. var defines a variable while let defines a constant
  2. var defined function scoped variable while let define block scoped variable
  3. The value of a variable declared with var can be changed while the value of a variable declared with let cannot be changed
  4. All of the above

Answer: B] var defined function scoped variable while let define block scoped variable

Explanation:

The var and let keywords are both used for variable declaration in JavaScript. But, the main difference between them is that var defines function scoped variable while let defines block-scoped variable.

Discuss this Question

22. The const keyword is used to define a ______.

  1. Function scopes variable
  2. Block scoped variable
  3. Constant
  4. Constant with no initial value

Answer: C] Constant

Explanation:

The const keyword is used to define a constant.

Discuss this Question

23. Which is the correct syntax to declare a constant in JavaScript?

  1. const constant_name;
  2. constant_name const;
  3. constant_name const = value;
  4. const constant_name = value;

Answer: D] const constant_name = value;

Explanation:

The correct syntax to declare a constant is:

const constant_name = value;

Example:

const PI = 3.14; 

Discuss this Question

24. What will be the value of VALUE?


	const VALUE = 10;
	VALUE = 20;

  1. 10
  2. 20
  3. ValueError
  4. TypeError

Answer: D] TypeError

Explanation:

We cannot change the value of a constant, thus the above code will generate a TypeError – "TypeError: Assignment to constant variable"

Discuss this Question

25. What is the default value of an uninitialized variable?

  1. 0
  2. undefined
  3. null
  4. NaN

Answer: B] undefined

Explanation:

The default value of an unfinalized variable is undefined.

Discuss this Question

26. What is the output of the following JavaScript code?


	var a;
	document.getElementById["demo"].innerHTML = a+1;

  1. 0
  2. undefined
  3. 1
  4. NaN

Answer: D] NaN

Explanation:

The output of the above JavaScript code is: NaN

Discuss this Question

27. Can be redeclare a variable that is declared with var keyword?

  1. Yes
  2. No

Answer: A] Yes

Explanation:

Yes, we can redeclare variable that is declared with var keyword.

Discuss this Question

28. What is the output of the following JavaScript code?


	var name = "Alex" + " " + "Alvin";
	document.getElementById["demo"].innerHTML = name;

  1. Alex Alvin
  2. AlexAlvin
  3. TypeError
  4. ValueError

Answer: A] Alex Alvin

Explanation:

The output of the above JavaScript code is: "Alex Alvin"

Discuss this Question

29. What is the output of the following JavaScript code?


	var a = 10 + 20 + "5";
	document.getElementById["demo"].innerHTML = a;

  1. 35
  2. 305
  3. TypeError
  4. ValueError

Answer: B] 305

Explanation:

The output of the above JavaScript code is: 305

Discuss this Question

30. Can be redeclare a variable that is declared with let keyword?

  1. Yes
  2. No

Answer: B] No

Explanation:

No, we cannot redeclare variable that is declared with let keyword.

Discuss this Question

31. What is the output of the following JavaScript code [let example]?


	let a = 10;
	let a = 0;

  1. 10
  2. 0
  3. SyntaxError
  4. TypeError

Answer: C] SyntaxError

Explanation:

The output of the above JavaScript code is: "SyntaxError: 'a' has already been declared".

Discuss this Question

32. Which is the exponentiation operator in JavaScript?

  1. exp[]
  2. ^
  3. **
  4. pow

Answer: C] **

Explanation:

The exponentiation operator in JavaScript is ** which is used to calculate the result of first operand's to the power of the second operators i.e., x**y = x to the power of y [xy].

Discuss this Question

33. Does JavaScript support increment [++] and decrements [--] Operators?

  1. Yes
  2. No

Answer: A] Yes

Explanation:

Yes, JavaScript supports increment [++] and decrements [--] operators.

Example:


	var x = 5;
	document.getElementById["test"].innerHTML = ++x;

Discuss this Question

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


	var x = 5;
	document.getElementById["demo"].innerHTML = x--;

  1. 5
  2. 4
  3. TypeError
  4. ValueError

Answer: B] 4

Explanation:

The output of the above statement will be 5.

In the above statement, we used post-decrement [x--]. Post-decrement decreases the value by 1 after evaluating the current statement.

Discuss this Question

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


	var x = 10 + 20 * 5;
	document.getElementById["tes"].innerHTML = x;

  1. 110
  2. 150
  3. TypeError
  4. ValueError

Answer: A] 110

Explanation:

The output of the above statement will be 110.

In the above code, the expression is 10 + 20 * 5. The precedence of multiplication operator [*] is higher than the addition operator [+]. This 20 *5 will evaluate first.

Discuss this Question

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


	var x = [10 + 20] * 5;
	document.getElementById["tes"].innerHTML = x;

  1. 110
  2. 150
  3. TypeError
  4. ValueError

Answer: B] 150

Explanation:

The output of the above statement will be 150.

In the above code, the expression is [10 + 20] * 5. The precedence of [] are higher than any other operators This [10 + 20] will evaluate first.

Discuss this Question

37. JavaScript types are _____.

  1. Static
  2. Dynamic

Answer: B] Dynamic

Explanation:

JavaScript types are dynamic, which means the same variable can be used to store the different types of values.

Discuss this Question

38. JavaScript arrays are written with _____.

  1. round brackets []
  2. curly brackets {}
  3. double quotes ""
  4. square brackets []

Answer: D] square brackets []

Explanation:

JavaScript arrays are written with square brackets [].

Discuss this Question

39. JavaScript objects are written with _____.

  1. round brackets []
  2. curly brackets {}
  3. double quotes ""
  4. square brackets []

Answer: B] curly brackets {}

Explanation:

JavaScript objects are written with curly brackets {}.

Discuss this Question

40. Which JavaScript operator is used to determine the type of a variable?

  1. typeof
  2. TypeOf
  3. typeOf
  4. sizeof

Answer: A] typeof

Explanation:

The typeof operator is used to determine the type of a variable.

Discuss this Question

41. Which is the correct syntax of JavaScript typeof operator?

  1. typeof variable/value
  2. typeof[variable/value]
  3. Both A. and B.
  4. None of the above

Answer: C] Both A. and B.

Explanation:

Both of the syntaxes can be used for JavaScript typeof operator.

Discuss this Question

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


	var x = 12.34;
	document.getElementById["test"].innerHTML = typeof[x];

  1. int
  2. float
  3. long
  4. number

Answer: D] number

Explanation:

The output of the following JavaScript code is number.

Discuss this Question

43. Which keyword is used to define a JavaScript function?

  1. module
  2. fun
  3. func
  4. function

Answer: D] function

Explanation:

The function keyword is used to define the JavaScript function.

Discuss this Question

44. Which is the correct syntax for the function definition?

  1. return_type function function_name[parameter1, parameter2, ...] { /*Function's body*/ }
  2. function function_name[parameter1, parameter2, ...] { /*Function's body*/ }
  3. return_type function_name[parameter1, parameter2, ...] { /*Function's body*/ }
  4. function function_name[parameter1, parameter2, ...] as return_type { /*Function's body*/ }

Answer: B] function function_name[parameter1, parameter2, ...] { /*Function's body*/ }

Explanation:

The function definition syntax is:

function function_name[parameter1, parameter2, ...]
{ 
	/*Function's body*/ 
}

Discuss this Question

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


	function addition[a, b] {
		return a+b;
	}
	document.getElementById["test"].innerHTML = addition;

  1. SyntaxError
  2. ValueError
  3. 0
  4. function addition[a, b] { return a+b; }

Answer: D] function addition[a, b] { return a+b; }

Explanation:

Calling of a function without [] will return the function definition i.e., function object instead of the result.

Discuss this Question

46. Can we use a function as a variable value?

  1. Yes
  2. No

Answer: A] Yes

Explanation:

Yes, a function can be used as a variable value.

Discuss this Question

47. In JavaScript a variable contains one value while an object may contain ___.

  1. One value
  2. Two values
  3. Three values
  4. Many values

Answer: D] Many values

Explanation:

In JavaScript a variable contains one value while an object may contain many values.

Discuss this Question

48. Which is the correct syntax to access an object property in JavaScript?

  1. objectName:propertyName
  2. propertyName
  3. objectName["propertyName"]
  4. Both B. and C.

Answer: D] Both B. and C.

Explanation:

The properties of an object can we accessed using either objectName.propertyName or objectName["propertyName"].

Discuss this Question

49. Which property is used to get the length of a string in JavaScript?

  1. strlen
  2. len
  3. length
  4. Length

Answer: C] length

Explanation:

The length property is used to get the length of a string in JavaScript.

Discuss this Question

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


	let str = "IncludeHelp";
	document.getElementById["test"].innerHTML = str.length;

  1. 11
  2. 12
  3. ValueError
  4. SyntaxError

Answer: A] 11

Explanation:

The output of the above statement will be the length of the string. That is 11.

Discuss this Question

51. Which character is used to break up a code line within a text string in JavaScript?

  1. Single quote [']
  2. Single backslash [\]
  3. Double quote ["]
  4. Tipple single quote [''']

Answer: B] Single backslash [\]

Explanation:

The Single backslash [\] is used to break up a code line within a text string in JavaScript.

Example:

document.getElementById["test"].innerHTML = "Hello \
IncludeHelp!";

Discuss this Question

52. Will the following JavaScript code work?


	document.getElementById["test"].innerHTML = \
	"Hello, IncludeHelp!";

  1. Yes
  2. No

Answer: B] No

Explanation:

No, the above code will not work. Because, we cannot breakup a JavaScript code line with single backslash [\].

Discuss this Question

53. Which is the correct JavaScript statement to define string as object?

  1. var s = new String["IncludeHelp!"];
  2. var s = String["IncludeHelp!"];
  3. var s = "IncludeHelp!"
  4. All of the above

Answer: A] var s = new String["IncludeHelp!"];

Explanation:

The strings can also be defined as an object using the new keyword. The correct JavaScript statement to define a string as an object is:

var s = new String["IncludeHelp!"];

Discuss this Question

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


	let str1 = new String["IncludeHelp!"];
	let str2 = new String["IncludeHelp!"];
	document.getElementById["test"].innerHTML = [str1==str2];

  1. true
  2. false
  3. True
  4. False

Answer: B] false

Explanation:

In the above code, str1 and str2 are the objects. And. In the JavaScript, comparison of two objects returns false.

Discuss this Question

55. Which is/are the valid JavaScript method[s] to extract string parts?

  1. slice[start, end]
  2. substring[start, end]
  3. substr[start, length]
  4. All of the above

Answer: D] All of the above

Explanation:

The all of the above JavaScript methods can be used to extract string parts.

Discuss this Question

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


    let x = "Hello, IncludeHelp!";
    document.getElementById["test"].innerHTML = x.slice[-13,-1];

  1. IncludeHelp!
  2. IncludeHelp
  3. ValueError
  4. Hello,

Answer: B] IncludeHelp

Explanation:

The negative value counts from the end of the string. Thus, the output will be "IncludeHelp".

Discuss this Question

57. In JavaScript, the string template literals use ____ rather than the quotes [""] to define a string?

  1. Single quotes ['']
  2. Backslash with single quote [\’'\']
  3. Backslashes [\\]
  4. Back-ticks [``]

Answer: D] Back-ticks [``]

Explanation:

In JavaScript, the string template literals use back-ticks [``] rather than the quotes [""] to define a string.

Discuss this Question

58. Does the following JavaScript variable definition is correct?

let x = `I'm "David!"`;
  1. Yes
  2. No

Answer: A] Yes

Explanation:

The JavaScript variable definition statement is true. Because, with the JavaScript template literals, we can use both single and double quotes inside a string.

Discuss this Question

59. Which JavaScript method is used to get a number as a string?

  1. toString[]
  2. intToString[]
  3. parseInteger[]
  4. All of the above

Answer: A] toString[]

Explanation:

The JavaScript method toString[] is used to get a number as a string.

Discuss this Question

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


    const myArray = ['h', 'e', 'l', 'l', 'o'];
    document.write[myArray[0]];
    document.write[myArray[1]];

  1. he
  2. undefinedh
  3. ValueError
  4. TypeError

Answer: A] he

Explanation:

In JavaScript, the array indexing starts with 0. Thus, the above statement with print "h" and "e".

Discuss this Question

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


    let cars = ['Honda', 'Hyundai'];
    cars.push['Mahindra'];
    document.write[typeof cars + " " + cars];

  1. array Honda,Hyundai,Mahindra
  2. string Honda,Hyundai,Mahindra
  3. object Honda,Hyundai,Mahindra
  4. object "Honda", "Hyundai", "Mahindra"

Answer: C] object "Honda", "Hyundai", "Mahindra"

Explanation:

The push[] method pushes an element at the end of the array. And, typeof returns the type of the object. Here, cars is an array.

Discuss this Question

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


    let cars1 = ['Honda', 'Hyundai'];
    let cars2 = cars1;
    
    cars1.push['Mahinda'];
    
    document.write[cars1 + "---" + cars2];

  1. Honda,Hyundai,Mahinda---Honda,Hyundai
  2. Honda,Hyundai,Mahinda---Honda,Hyundai,Mahinda
  3. Honda,Hyundai ---Honda,Hyundai
  4. [Honda,Hyundai,Mahinda]---[Honda,Hyundai,Mahinda]

Answer: B] Honda,Hyundai,Mahinda---Honda,Hyundai,Mahinda

Explanation:

In the JavaScript, the arrays are objects, and the array elements are stored by reference. Hence, when an array value is copied, any change in the copied array will also reflect in the original array. Thus, the values of cars1 and cars2 are the same.

Discuss this Question

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

  
	var msgs=new Array["Hello","Hey","Morning!"];  

	for [i=0;i

Bài mới nhất

Chủ Đề