1Which HTML tag is used to embed JavaScript code inside a webpage?
A.<code>
B.<javascript>
C.<js>
D.<script>
Correct Answer: <script>
Explanation:
The <script> tag is the standard HTML element used to define client-side scripts, such as JavaScript.
Incorrect! Try again.
2Which attribute of the <script> tag is used to include an external JavaScript file?
A.href
B.src
C.link
D.rel
Correct Answer: src
Explanation:
The 'src' attribute specifies the URL of an external script file.
Incorrect! Try again.
3Where is the correct place to insert a JavaScript in an HTML document?
A.The <body> section
B.The <head> section
C.Both the <head> section and the <body> section
D.The <footer> section
Correct Answer: Both the <head> section and the <body> section
Explanation:
JavaScript can be placed in both the <head> and <body> sections of an HTML page, depending on when the script needs to load.
Incorrect! Try again.
4What is the correct file extension for an external JavaScript file?
A..html
B..script
C..java
D..js
Correct Answer: .js
Explanation:
External JavaScript files are saved with the .js extension.
Incorrect! Try again.
5How do you write 'Hello World' in an alert box?
A.alert('Hello World');
B.msg('Hello World');
C.alertBox('Hello World');
D.msgBox('Hello World');
Correct Answer: alert('Hello World');
Explanation:
The alert() function is used to display a popup box with a specified message.
Incorrect! Try again.
6Which keyword is used to declare a variable that cannot be reassigned?
A.static
B.var
C.const
D.let
Correct Answer: const
Explanation:
The 'const' keyword defines a variable as a constant, meaning its value cannot be reassigned after initialization.
Incorrect! Try again.
7What is the scope of a variable declared with 'let' inside a block?
A.Block scope
B.Module scope
C.Global scope
D.Function scope
Correct Answer: Block scope
Explanation:
Variables declared with 'let' are limited to the block, statement, or expression on which they are used.
Incorrect! Try again.
8Which operator is used to check both value and type equality?
A.===
B.==
C.!=
D.=
Correct Answer: ===
Explanation:
The strict equality operator (===) checks if two values are equal in both value and data type.
Incorrect! Try again.
9What is the result of the expression: '5' + 3?
A.53
B.NaN
C.8
D.Error
Correct Answer: 53
Explanation:
When a number is added to a string, JavaScript converts the number to a string and concatenates them.
Incorrect! Try again.
10Which function is used to get input from the user?
A.confirm()
B.input()
C.prompt()
D.alert()
Correct Answer: prompt()
Explanation:
The prompt() method displays a dialog box that prompts the visitor for input.
Incorrect! Try again.
11What does the confirm() method return?
A.Integer
B.String
C.Boolean
D.Object
Correct Answer: Boolean
Explanation:
The confirm() method returns true if the user clicks OK, and false if the user clicks Cancel.
Incorrect! Try again.
12How does a 'while' loop start?
A.while i = 1 to 10
B.until (i <= 10)
C.while (i <= 10)
D.while (i <= 10; i++)
Correct Answer: while (i <= 10)
Explanation:
The syntax for a while loop is 'while (condition)'. It continues as long as the condition is true.
Incorrect! Try again.
13Which statement is used to stop a loop completely?
A.break
B.return
C.stop
D.continue
Correct Answer: break
Explanation:
The 'break' statement terminates the current loop or switch statement and transfers control to the statement following the terminated statement.
Incorrect! Try again.
14What is the purpose of the 'continue' statement?
A.Stops the loop execution
B.Restarts the loop
C.Skips the current iteration
D.Exits the function
Correct Answer: Skips the current iteration
Explanation:
The 'continue' statement breaks one iteration (in the loop), if a specified condition occurs, and continues with the next iteration.
Incorrect! Try again.
15Which loop is guaranteed to execute at least once?
A.for
B.while
C.foreach
D.do...while
Correct Answer: do...while
Explanation:
A do...while loop executes the code block once before checking if the condition is true, then it will repeat the loop as long as the condition is true.
Incorrect! Try again.
16How do you write an IF statement in JavaScript?
A.if i = 5 then
B.if i = 5
C.if (i == 5)
D.if i == 5 then
Correct Answer: if (i == 5)
Explanation:
The correct syntax for an if statement requires the condition to be enclosed in parentheses: if (condition).
Incorrect! Try again.
17How do you write an IF statement for executing some code if 'i' is NOT equal to 5?
A.if (i <> 5)
B.if i not 5
C.if i =! 5 then
D.if (i != 5)
Correct Answer: if (i != 5)
Explanation:
The operator != represents 'not equal to' in JavaScript.
Incorrect! Try again.
18Which symbol is used for single-line comments in JavaScript?
A.**
B.//
C.<!-- -->
D.//
Correct Answer: //
Explanation:
Double slashes (//) are used for single-line comments in JavaScript.
Incorrect! Try again.
19What 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'>
Correct Answer: <script src='app.js'>
Explanation:
The 'src' attribute is strictly used to link external JavaScript files.
Incorrect! Try again.
20How do you create a JavaScript object?
A.var obj = ();
B.var obj = [];
C.var obj = <>;
D.var obj = {};
Correct Answer: var obj = {};
Explanation:
Curly braces {} are used to define an object literal in JavaScript.
Incorrect! Try again.
21Given: var person = {firstName:'John', lastName:'Doe'}; How do you access the lastName?
A.person::lastName
B.person.lastName
C.person[lastName]
D.person->lastName
Correct Answer: person.lastName
Explanation:
Object properties are accessed using dot notation (object.property) or bracket notation with quotes (object['property']).
Incorrect! Try again.
22Which keyword is used to define a variable in JavaScript (ES5 legacy)?
A.string
B.var
C.int
D.dim
Correct Answer: var
Explanation:
The 'var' keyword was the original way to declare variables in JavaScript before ES6 introduced 'let' and 'const'.
Incorrect! Try again.
23What is the correct way to write a JavaScript array?