Unit 4: JavaScript Application Development - Practice Quiz

CSE326 — Internet Programming Laboratory 50 Questions
0 Correct 0 Wrong 50 Left
0/50

1 Which HTML tag is used to embed JavaScript code inside a webpage?

A. <js>
B. <javascript>
C. <script>
D. <code>

2 Which attribute of the <script> tag is used to include an external JavaScript file?

A. link
B. rel
C. href
D. src

3 Where is the correct place to insert a JavaScript in an HTML document?

A. The <head> section
B. Both the <head> section and the <body> section
C. The <body> section
D. The <footer> section

4 What is the correct file extension for an external JavaScript file?

A. .html
B. .js
C. .java
D. .script

5 How do you write 'Hello World' in an alert box?

A. alert('Hello World');
B. alertBox('Hello World');
C. msgBox('Hello World');
D. msg('Hello World');

6 Which keyword is used to declare a variable that cannot be reassigned?

A. var
B. const
C. let
D. static

7 What is the scope of a variable declared with 'let' inside a block?

A. Block scope
B. Module scope
C. Function scope
D. Global scope

8 Which operator is used to check both value and type equality?

A. !=
B. ==
C. =
D. ===

9 What is the result of the expression: '5' + 3?

A. 8
B. NaN
C. 53
D. Error

10 Which function is used to get input from the user?

A. prompt()
B. alert()
C. input()
D. confirm()

11 What does the confirm() method return?

A. Object
B. String
C. Integer
D. Boolean

12 How does a 'while' loop start?

A. while (i <= 10; i++)
B. while (i <= 10)
C. until (i <= 10)
D. while i = 1 to 10

13 Which statement is used to stop a loop completely?

A. break
B. return
C. continue
D. stop

14 What is the purpose of the 'continue' statement?

A. Restarts the loop
B. Stops the loop execution
C. Exits the function
D. Skips the current iteration

15 Which loop is guaranteed to execute at least once?

A. foreach
B. do...while
C. for
D. while

16 How do you write an IF statement in JavaScript?

A. if i = 5
B. if i = 5 then
C. if (i == 5)
D. if i == 5 then

17 How do you write an IF statement for executing some code if 'i' is NOT equal to 5?

A. if i not 5
B. if (i <> 5)
C. if i =! 5 then
D. if (i != 5)

18 Which symbol is used for single-line comments in JavaScript?

A. **
B. / /
C. //
D. <!-- -->

19 What is the correct syntax for referring to an external script called 'app.js'?

A. <script href='app.js'>
B. <script file='app.js'>
C. <script src='app.js'>
D. <script name='app.js'>

20 How do you create a JavaScript object?

A. var obj = ();
B. var obj = [];
C. var obj = {};
D. var obj = <>;

21 Given: var person = {firstName:'John', lastName:'Doe'}; How do you access the lastName?

A. person[lastName]
B. person->lastName
C. person.lastName
D. person::lastName

22 Which keyword is used to define a variable in JavaScript (ES5 legacy)?

A. string
B. dim
C. int
D. var

23 What is the correct way to write a JavaScript array?

A. var colors = 'red', 'green', 'blue'
B. var colors = 1 = ('red'), 2 = ('green'), 3 = ('blue')
C. var colors = ['red', 'green', 'blue']
D. var colors = (1:'red', 2:'green', 3:'blue')

24 Inside which HTML element do we put the JavaScript?

A. <script>
B. <scripting>
C. <js>
D. <javascript>

25 What will be the output of: typeof 'Hello'?

A. String
B. text
C. string
D. object

26 Which statement serves as the fall-back in a 'switch' statement?

A. else
B. default
C. break
D. case

27 What is the correct syntax for a 'for' loop?

A. for (i = 0; i <= 5; i++)
B. for (i = 0; i <= 5)
C. for i = 1 to 5
D. for (i <= 5; i++)

28 How can you add a comment that has more than one line?

A. <!-- This is a comment -->
B. // This is a comment //
C. / This is a comment /
D. This is a comment

29 Which operator is used to assign a value to a variable?

A. *
B. ==
C. -
D. =

30 What is the value of 'x' after: var x = 10; x += 5;

A. 5
B. 15
C. 10
D. Error

31 Which keyword identifies a block of code to be executed if a specified condition is false?

A. break
B. then
C. stop
D. else

32 In an object method, what does 'this' refer to?

A. The function itself
B. The global object
C. The owner object
D. The variable name

33 Which logical operator represents 'OR'?

A. &
B. !
C. ||
D. &&

34 What is the correct way to check if a variable 'car' is undefined?

A. if (car is undefined)
B. if (car == null)
C. if (car === undefined)
D. if (typeof car == 'undefined')

35 Which of the following is NOT a valid JavaScript variable name?

A. _myVar
B. 2myVar
C. myVar2
D. $myVar

36 What syntax is used to access a method 'start' of an object 'engine'?

A. call engine.start
B. engine.start()
C. engine->start()
D. engine['start']

37 What happens if you redeclare a variable using 'let' in the same scope?

A. It creates a new variable
B. It overwrites the previous value
C. It causes a SyntaxError
D. Nothing happens

38 Which property is used to find the length of a string?

A. length
B. len
C. count
D. size

39 What is the output of Boolean(10 > 9)?

A. false
B. undefined
C. NaN
D. true

40 Which is the ternary operator?

A. ||
B. ?:
C. ??
D. &&

41 What keyword defines a switch case block?

A. if
B. when
C. option
D. case

42 How do you delete a property from a JavaScript object?

A. remove object.property
B. delete object.property
C. object.property = null
D. clear object.property

43 Which popup box returns null if the user clicks 'Cancel'?

A. confirm
B. prompt
C. alert
D. message

44 What is Hoisting in JavaScript?

A. Moving declarations to the top
B. Looping efficiently
C. Moving initializations to the top
D. Deleting unused variables

45 Which of the following is a valid const declaration?

A. const PI;
B. const PI = 3.14;
C. const 3.14 = PI;
D. const PI = 3.14; PI = 3.14159;

46 What loop is best suited for iterating over the properties of an object?

A. for...in
B. while
C. do...while
D. for

47 Which symbol is used for the modulus (remainder) operator?

A. &
B. *
C. /
D. %

48 If x = 10 and y = '10', what is the result of x == y?

A. true
B. undefined
C. false
D. NaN

49 If x = 10 and y = '10', what is the result of x === y?

A. undefined
B. false
C. true
D. NaN

50 Which global object do alert(), confirm(), and prompt() belong to?

A. console
B. window
C. html
D. document