Answer: b) Displays a pop-up message box
Explanation: The alert() function displays a pop-up message box with text.
Answer: c) alert("Welcome!")
Explanation: alert("message") is the correct syntax for showing a message in an alert box.
Answer: b) It shows 55
Explanation: The number 5 is converted to a string, so "5" + 5 becomes "55".
Answer: c) Hello World!
Explanation: Strings are concatenated with +, including the space " ".
Answer: b) It returns a value
Explanation: alert() doesn’t return a value; it just shows a message.
Answer: c) var name = "Ali";
Explanation: In JavaScript, strings are enclosed in quotes and declared using var, let, or const.
Answer: c) Hello!
Explanation: The variable message contains the string "Hello!", which is shown in the alert.
Answer: b) var msg = 'Hello!';
Explanation: Strings must be enclosed in quotes. Both single and double quotes work.
Answer: c) Hi Sara
Explanation: The + operator concatenates strings. "Hi" + " " + "Sara" becomes "Hi Sara".
Answer: b) Declares a string variable
Explanation: This line declares a variable msg and assigns it a string value.
Answer: b) var 1name = "Ali";
Explanation: Variable names cannot start with a number.
Answer: b) It shows undefined
Explanation: Due to hoisting, city exists but has undefined until it is assigned a value.
Answer: b) 205
Explanation: Both are strings, so the + operator concatenates them into "205".
Answer: b) Text data enclosed in quotes
Explanation: A string is any sequence of characters enclosed in single or double quotes.
Answer: a) My favorite animal is a cat.
Explanation: The string "My favorite animal is a " + animal + "." becomes "My favorite animal is a cat."
Answer: b) var num = 5;
Explanation: Numbers should be assigned without quotes in JavaScript.
Answer: b) 30
Explanation: 10 + 20 = 30 since both are numbers.
Answer: b) 55
Explanation: Number 5 is converted to a string, so it becomes "5" + "5" = "55".
Answer: c) They can be decimal numbers
Explanation: JavaScript number variables can be integers or floating-point numbers.
Answer: a) 20
Explanation: The multiplication 10 * 2 results in 20.
Answer: a) 108
Explanation: Both variables hold numbers, so 100 + 8 = 108.
Answer: b) 5 - 3
Explanation: Subtraction in JavaScript is done with the - operator, like in 5 - 3.
Answer: b) 15
Explanation: x is reassigned to 10 + 5, which is 15.
Answer: a) 1.5
Explanation: 3 / 2 results in 1.5 (JavaScript supports decimals).
Answer: c) "20"
Explanation: "20" is a string, not a number—even though it looks like one.
Answer: c) _userName
Explanation: Legal variable names can start with letters, $, or _. 1stName starts with a number, user-name contains a hyphen, and var is a reserved keyword.
Answer: c) It causes a syntax error
Explanation: Spaces are not allowed in variable names.
Answer: c) let
Explanation: let is a reserved keyword in JavaScript and cannot be used as a variable name.
Answer: c) It includes a hyphen
Explanation: Hyphens - are interpreted as the minus operator, making user-name invalid.
Answer: d) camelCase
Explanation: JavaScript typically uses camelCase for variable names, e.g., userName.
Answer: c) fullName
Explanation: camelCase starts with a lowercase letter and capitalizes the first letter of each subsequent word.
Answer: c) It throws a syntax error
Explanation: Reserved keywords like function cannot be used as variable names; it causes a syntax error.
Answer: b) _
Explanation: A variable name can start with a letter, $, or _.
Answer: c) userAge
Explanation: userAge clearly indicates the purpose of the variable and follows naming conventions.
Answer: c) No official limit, but practical limits apply
Explanation: JavaScript doesn't have an official limit, but long variable names are discouraged for readability.
Answer: c) Adds the numbers
Explanation: The + operator performs addition when both operands are numbers.
Answer: a) 6
Explanation: 10 - 4 evaluates to 6.
Answer: b) *
Explanation: JavaScript uses the asterisk * for multiplication.
Answer: a) 5
Explanation: 10 / 2 equals 5.
Answer: a) %
Explanation: The % operator returns the remainder after division.
Answer: a) 10
Explanation: x is reassigned as 7 + 3, which equals 10.
Answer: b) 150
Explanation: 200 - 50 equals 150.
Answer: c) Multiplies 3 by 4
Explanation: The * operator performs multiplication.
Answer: d) All of the above
Explanation:
10 - 8 = 2
2 + 0 = 2
10 % 4 = 2 (since 4 * 2 = 8, remainder = 2)
Answer: a) 7
Explanation: x is updated to 12 - 5 = 7.
Answer: b) Increases the variable’s value by 1
Explanation: The ++ operator is a shorthand for incrementing a variable by 1.
Answer: b) 6
Explanation: x++ increases the value of x by 1 after its current value is used.
Answer: c) Decreases the value by 1
Explanation: The -- operator decrements the variable’s value by 1.
Answer: b) 11
Explanation: ++a is a pre-increment. It adds 1 before displaying, so 10 becomes 11.
Answer: a) 7
Explanation: b-- is a post-decrement, so it shows 7 and then changes b to 6.
Answer: b) 6
Explanation: x is incremented twice: 4 → 5 → 6.
Answer: b) 7
Explanation: Pre-decrement --y subtracts 1 before alerting: 8 → 7.
Answer: b) x += 1
Explanation: x += 1 is a shorthand for x = x + 1.
Answer: a) x++ increments after use, ++x increments before use
Explanation: Post-increment (x++) increases value after it's used; pre-increment (++x) increases it before use.
Answer: a) 5
Explanation: a++ assigns 5 to b first, then increments a to 6.
Answer: b) It determines the order in which operations are evaluated
Explanation: Operator precedence controls which operations are performed first when multiple operators are used.
Answer: d) 25
Explanation: Multiplication has higher precedence than addition, so 5 * 2 = 10, then 10 + 15 = 25.
Answer: c) Using parentheses ()
Explanation: Parentheses change the default order of operations, forcing inner operations to be evaluated first.
Answer: a) 30
Explanation: Parentheses force 10 + 5 = 15, then 15 * 2 = 30.
Answer: c) Parentheses ()
Explanation: Parentheses always have the highest precedence and are evaluated first.
Answer: b) 13
Explanation: Multiplication first: 2 * 3 = 6; then 8 + 6 = 14; finally 14 - 1 = 13.
Answer: b) 4 * 3
Explanation: Parentheses are evaluated first: 4 * 3 = 12.
Answer: a) Left to right
Explanation: Operators of equal precedence (- and +) are evaluated left to right: 20 - 3 = 17, then 17 + 2 = 19.
Answer: c) Add parentheses
Explanation: Parentheses help remove ambiguity: e.g., base + (tax / 100 * base) or better structured as needed.
Answer: a) 15
Explanation: (2 + 3) = 5, (4 - 1) = 3, then 5 * 3 = 15.
Answer: c) Concatenates (joins) the strings
Explanation: In JavaScript, the + operator joins strings when used with string values.
Answer: b) Ali Khan
Explanation: It concatenates the first and last name with a space between them.
Answer: b) "Hi" + "There" + "Friend"
Explanation: The + operator joins multiple strings in order.
Answer: c) Total: 105
Explanation: String + number = string. So "Total: " + 10 becomes "Total: 10", then "Total: 10" + 5 = "Total: 105".
Answer: b) Add numbers inside parentheses
Explanation: Parentheses change the evaluation order. Example: "Total: " + (10 + 5) → "Total: 15"
Answer: a) HelloJohn
Explanation: The strings "Hello" and "John" are concatenated without a space between them.
Answer: b) "Hello" + " " + "World"
Explanation: You need to explicitly add a space between the strings using " ".
Answer: a) The sum is: 510
Explanation: The + operator concatenates the string with num1, then num2, forming "The sum is: 510".
Answer: a) concat()
Explanation: The concat() method joins two or more strings in JavaScript.
Answer: c) 321
Explanation: "3" + 2 = "32", then "32" + 1 = "321".
Answer: a) Good Morning
Explanation: The code concatenates "Good" and "Morning" with a space between.
Answer: b) 2030
Explanation: "20" + "30" results in the string "2030".
Answer: a) Hello52
Explanation: "Hello" + 5 = "Hello5", then "Hello5" + 2 = "Hello52".
Answer: a) John Doe is 30 years old.
Explanation: This concatenates all parts to form the sentence.
Answer: c) The array elements are joined together as a string
Explanation: Example: "Hello" + [1, 2, 3] results in "Hello123".
Answer: B) To ask the user for input
Explanation: The prompt() method is used to display a dialog box asking the user for input.
Answer: A) It asks the user to enter their name and then displays a greeting
Explanation: The prompt() method asks the user for input and stores it in the name variable. Then, the alert() displays a greeting with the entered name.
Answer: A) String
Explanation: The prompt() method always returns the input as a string, even if the user enters a number.
Answer: A) You are John years old.
Explanation: If the user enters "John", it will be treated as a string, and the message will be "You are John years old.".
Answer: D) Both A and B
Explanation: You can use parseInt() or parseFloat() to convert the user input into a number, or use Number() for automatic conversion.
Answer: B) NaN
Explanation: The value returned by prompt() is always a string, so multiplying a string ("25") by 2 results in NaN (Not a Number).
Answer: D) All of the above
Explanation: All of the methods (parseInt(), parseFloat(), and Number()) can be used to convert a string to a number.
Answer: A) It returns null
Explanation: When the user clicks "Cancel", the prompt() method returns null.
var age = prompt("What is your age?"); if (isNaN(age)) { alert("Please enter a valid number."); }B)
var age = prompt("What is your age?"); if (typeof age === "number") { alert("Valid number entered."); }C)
var age = prompt("What is your age?"); if (age === "NaN") { alert("Please enter a valid number."); }D)
var age = prompt("What is your age?"); alert(age);
Answer: A
Explanation: Using isNaN() checks whether the entered value is not a number, ensuring the input is valid.
Answer: A) It alerts the squared value of the input
Explanation: If the user enters a number, it will be squared and the result will be displayed. If the input is not a number, it might result in NaN due to the way prompt() returns a string.
Answer: C) To make decisions based on a condition
Explanation: An if statement allows JavaScript to execute a block of code only if a specified condition is true.
Answer: A) if (condition) { statement; }
Explanation: The correct syntax for an if statement in JavaScript is if (condition) { statement; }.
Answer: A) x is greater than 5
Explanation: Since the condition x > 5 is true, the code inside the if block is executed, showing the message "x is greater than 5".
Answer: A) The number is 20
Explanation: The condition num == 20 is true, so the code inside the if block is executed, and the message "The number is 20" is shown.
Answer: C) ===
Explanation: The === operator checks both value and type equality, making it a stricter comparison than ==, which only compares values.
Answer: B) The code inside the if block will not execute
Explanation: If the condition is false, the code inside the if block will not execute.
Answer: A) An if statement can have multiple conditions combined using logical operators
Explanation: You can combine multiple conditions in an if statement using logical operators like && (AND) and || (OR).
Answer: B) You are a minor.
Explanation: Since age is 16, which is less than 18, the else block is executed, displaying "You are a minor.".
Answer: A) It's hot outside.
Explanation: Since temperature is 30, which is greater than 20, the first condition is true, and "It's hot outside." is displayed.
Answer: A) Negative number
Explanation: Since number is -5, the first condition number < 0 is true, and the message "Negative number" is displayed.
Answer: B) Falsy value
Explanation: In JavaScript, 0 is considered a falsy value, so the else block will execute, showing "Falsy value".
Answer: B) The code will execute without any issues
Explanation: An if statement can exist without an else block. If the condition is false, simply nothing happens, and the code continues.
Answer: A) Positive or Non-zero number
Explanation: The value -10 is considered a truthy value in JavaScript, so the code will display "Positive or Non-zero number".
Answer: A) else if is used to check multiple conditions sequentially
Explanation: The else if statement allows for checking additional conditions after the initial if, enabling multiple conditions to be tested sequentially.
Answer: A) num1 is less than num2
Explanation: Since num1 (20) is less than num2 (30), the condition num1 < num2 is true, and the message "num1 is less than num2" is displayed.