Notice: Due to an ongoing migration of our storage and publishing system, material requested since last month will not be uploaded for the time being, and new requests are paused. All existing notes remain available.
Which HTML tag is used to embed JavaScript code inside a webpage?
Not quite. Try another option.
Answer: <script>
The <script> tag is the standard HTML element used to define client-side scripts, such as JavaScript.
Question 2 of 50
Which attribute of the <script> tag is used to include an external JavaScript file?
Not quite. Try another option.
Answer: src
The 'src' attribute specifies the URL of an external script file.
Question 3 of 50
Where is the correct place to insert a JavaScript in an HTML document?
Not quite. Try another option.
Answer: Both the <head> section and the <body> section
JavaScript can be placed in both the <head> and <body> sections of an HTML page, depending on when the script needs to load.
Question 4 of 50
What is the correct file extension for an external JavaScript file?
Not quite. Try another option.
Answer: .js
External JavaScript files are saved with the .js extension.
Question 5 of 50
How do you write 'Hello World' in an alert box?
Not quite. Try another option.
Answer: alert('Hello World');
The alert() function is used to display a popup box with a specified message.
Question 6 of 50
Which keyword is used to declare a variable that cannot be reassigned?
Not quite. Try another option.
Answer: const
The 'const' keyword defines a variable as a constant, meaning its value cannot be reassigned after initialization.
Question 7 of 50
What is the scope of a variable declared with 'let' inside a block?
Not quite. Try another option.
Answer: Block scope
Variables declared with 'let' are limited to the block, statement, or expression on which they are used.
Question 8 of 50
Which operator is used to check both value and type equality?
Not quite. Try another option.
Answer: ===
The strict equality operator (===) checks if two values are equal in both value and data type.
Question 9 of 50
What is the result of the expression: '5' + 3?
Not quite. Try another option.
Answer: 53
When a number is added to a string, JavaScript converts the number to a string and concatenates them.
Question 10 of 50
Which function is used to get input from the user?
Not quite. Try another option.
Answer: prompt()
The prompt() method displays a dialog box that prompts the visitor for input.
Question 11 of 50
What does the confirm() method return?
Not quite. Try another option.
Answer: Boolean
The confirm() method returns true if the user clicks OK, and false if the user clicks Cancel.
Question 12 of 50
How does a 'while' loop start?
Not quite. Try another option.
Answer: while (i <= 10)
The syntax for a while loop is 'while (condition)'. It continues as long as the condition is true.
Question 13 of 50
Which statement is used to stop a loop completely?
Not quite. Try another option.
Answer: break
The 'break' statement terminates the current loop or switch statement and transfers control to the statement following the terminated statement.
Question 14 of 50
What is the purpose of the 'continue' statement?
Not quite. Try another option.
Answer: Skips the current iteration
The 'continue' statement breaks one iteration (in the loop), if a specified condition occurs, and continues with the next iteration.
Question 15 of 50
Which loop is guaranteed to execute at least once?
Not quite. Try another option.
Answer: do...while
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.
Question 16 of 50
How do you write an IF statement in JavaScript?
Not quite. Try another option.
Answer: if (i == 5)
The correct syntax for an if statement requires the condition to be enclosed in parentheses: if (condition).
Question 17 of 50
How do you write an IF statement for executing some code if 'i' is NOT equal to 5?
Not quite. Try another option.
Answer: if (i != 5)
The operator != represents 'not equal to' in JavaScript.
Question 18 of 50
Which symbol is used for single-line comments in JavaScript?
Not quite. Try another option.
Answer: //
Double slashes (//) are used for single-line comments in JavaScript.
Question 19 of 50
What is the correct syntax for referring to an external script called 'app.js'?
Not quite. Try another option.
Answer: <script src='app.js'>
The 'src' attribute is strictly used to link external JavaScript files.
Question 20 of 50
How do you create a JavaScript object?
Not quite. Try another option.
Answer: var obj = {};
Curly braces {} are used to define an object literal in JavaScript.
Question 21 of 50
Given: var person = {firstName:'John', lastName:'Doe'}; How do you access the lastName?
Not quite. Try another option.
Answer: person.lastName
Object properties are accessed using dot notation (object.property) or bracket notation with quotes (object['property']).
Question 22 of 50
Which keyword is used to define a variable in JavaScript (ES5 legacy)?
Not quite. Try another option.
Answer: var
The 'var' keyword was the original way to declare variables in JavaScript before ES6 introduced 'let' and 'const'.
Question 23 of 50
What is the correct way to write a JavaScript array?
Not quite. Try another option.
Answer: var colors = ['red', 'green', 'blue']
Arrays are defined using square brackets [].
Question 24 of 50
Inside which HTML element do we put the JavaScript?
Not quite. Try another option.
Answer: <script>
The standard HTML tag for embedding scripts is <script>.
Question 25 of 50
What will be the output of: typeof 'Hello'?
Not quite. Try another option.
Answer: string
The typeof operator returns the type of a variable. For string literals, it returns 'string'.
Question 26 of 50
Which statement serves as the fall-back in a 'switch' statement?
Not quite. Try another option.
Answer: default
The 'default' keyword specifies the code to run if there is no case match in a switch statement.
Question 27 of 50
What is the correct syntax for a 'for' loop?
Not quite. Try another option.
Answer: for (i = 0; i <= 5; i++)
A for loop requires three statements: initialization, condition, and increment/decrement.
Question 28 of 50
How can you add a comment that has more than one line?
Not quite. Try another option.
Answer: / This is a comment /
Multi-line comments in JavaScript start with / and end with /.
Question 29 of 50
Which operator is used to assign a value to a variable?
Not quite. Try another option.
Answer: =
The = operator is the assignment operator.
Question 30 of 50
What is the value of 'x' after: var x = 10; x += 5;
Not quite. Try another option.
Answer: 15
The += operator adds the value on the right to the variable on the left and assigns the result to the variable (x = x + 5).
Question 31 of 50
Which keyword identifies a block of code to be executed if a specified condition is false?
Not quite. Try another option.
Answer: else
The 'else' statement specifies a block of code to be executed if the condition in the 'if' statement is false.
Question 32 of 50
In an object method, what does 'this' refer to?
Not quite. Try another option.
Answer: The owner object
In a method, 'this' refers to the object that 'owns' the method.
Question 33 of 50
Which logical operator represents 'OR'?
Not quite. Try another option.
Answer: ||
The || operator represents logical OR.
Question 34 of 50
What is the correct way to check if a variable 'car' is undefined?
Not quite. Try another option.
Answer: if (typeof car == 'undefined')
Using typeof allows checking for undefined without throwing an error if the variable hasn't been declared.
Question 35 of 50
Which of the following is NOT a valid JavaScript variable name?
Not quite. Try another option.
Answer: 2myVar
Variable names cannot start with a number.
Question 36 of 50
What syntax is used to access a method 'start' of an object 'engine'?
Not quite. Try another option.
Answer: engine.start()
Methods are accessed using dot notation followed by parentheses to invoke the function.
Question 37 of 50
What happens if you redeclare a variable using 'let' in the same scope?
Not quite. Try another option.
Answer: It causes a SyntaxError
Variables declared with 'let' (and 'const') cannot be redeclared in the same scope.
Question 38 of 50
Which property is used to find the length of a string?
Not quite. Try another option.
Answer: length
The .length property returns the number of characters in a string.
Question 39 of 50
What is the output of Boolean(10 > 9)?
Not quite. Try another option.
Answer: true
The expression 10 > 9 is true, so Boolean() returns true.
Question 40 of 50
Which is the ternary operator?
Not quite. Try another option.
Answer: ?:
The conditional (ternary) operator is the only JavaScript operator that takes three operands: condition ? exprIfTrue : exprIfFalse.
Question 41 of 50
What keyword defines a switch case block?
Not quite. Try another option.
Answer: case
The 'case' keyword marks a block of code to be executed in a switch statement if the match is found.
Question 42 of 50
How do you delete a property from a JavaScript object?
Not quite. Try another option.
Answer: delete object.property
The 'delete' operator removes a property from an object.
Question 43 of 50
Which popup box returns null if the user clicks 'Cancel'?
Not quite. Try another option.
Answer: prompt
If the user clicks Cancel in a prompt box, the function returns null.
Question 44 of 50
What is Hoisting in JavaScript?
Not quite. Try another option.
Answer: Moving declarations to the top
Hoisting is JavaScript's default behavior of moving declarations (specifically var and function declarations) to the top of the current scope.
Question 45 of 50
Which of the following is a valid const declaration?
Not quite. Try another option.
Answer: const PI = 3.14;
Const variables must be assigned a value when they are declared.
Question 46 of 50
What loop is best suited for iterating over the properties of an object?
Not quite. Try another option.
Answer: for...in
The for...in loop iterates over the enumerable properties of an object.
Question 47 of 50
Which symbol is used for the modulus (remainder) operator?
Not quite. Try another option.
Answer: %
The % operator returns the division remainder.
Question 48 of 50
If x = 10 and y = '10', what is the result of x == y?
Not quite. Try another option.
Answer: true
The == operator performs type coercion, so the number 10 is equal to the string '10'.
Question 49 of 50
If x = 10 and y = '10', what is the result of x === y?
Not quite. Try another option.
Answer: false
The === operator does not perform type coercion. A number is not strictly equal to a string.
Question 50 of 50
Which global object do alert(), confirm(), and prompt() belong to?
Not quite. Try another option.
Answer: window
These popup methods are part of the browser's Window object.
That's unit 4
Answer a few questions and your score shows up here.
Nearly through. Did unit 4 of CSE326 save you a night before the exam?
LPU Notes is free. A student pays for the servers.
Did unit 4 of CSE326 save you a night before the exam?
Then you can help keep it free for the next batch. Ads cover part of the server bill;
the rest comes out of a student's own pocket: the domain, the storage, and keeping
the site up through the weeks everyone needs it at once.
The payment button didn't load. An ad blocker or a filtered network is the usual reason.
to try again.