Table of contents | |
Multiple Choice Questions (MCQs) | |
Higher Order Thinking Questions (HOTS) | |
Fill in the Blanks | |
True or False | |
Hands-On Questions |
Q.1. Which operator is used to concatenate strings in JavaScript?
(a) +
(b) *
(c) /
(d) -
Ans. (a)
Q.2. The comparison operator '===' in JavaScript checks for both value and ________.
(a) type
(b) length
(c) size
(d) presence
Ans. (a)
Q.3. The logical operator '&&' in JavaScript returns true if:
(a) both operands are true
(b) both operands are false
(c) either operand is true
(d) either operand is false
Ans. (a)
Q.4. What will be the output of the following code snippet?
let x = 10;
let y = 5;
console.log(x % y);
(a) 2
(b) 0
(c) 5
(d) 10
Ans. (b)
Q.5. Which operator is used to assign a value to a variable in JavaScript?
(a) =
(b) ==
(c) ===
(d) :
Ans. (a)
Q.1. Explain the difference between the '==' and '===' operators in JavaScript.
The '==' operator in JavaScript compares the values of the operands, performing type coercion if necessary. The '===' operator, on the other hand, compares both the values and types of the operands, without performing type coercion.
Q.2. Give an example of a ternary operator in JavaScript and explain how it works.
let result = (condition) ? value1 : value2;
The ternary operator in JavaScript is a concise way of writing an if-else statement. If the condition is true, it assigns value1 to the result; otherwise, it assigns value2.
Q.3. What is the purpose of the 'typeof' operator in JavaScript? Give an example.
The 'typeof' operator in JavaScript is used to determine the type of a variable or expression. Example:
let x = 5;
console.log(typeof x); // Output: "number"
Q.4. How does the 'delete' operator work in JavaScript? Provide an example.
The 'delete' operator in JavaScript is used to remove a property from an object. Example:
let person = {
name: "John",
age: 30
};
delete person.age;
console.log(person); // Output: { name: "John" }
Q.5. Explain the concept of short-circuiting in JavaScript using the logical operators '&&' and '||'.
Short-circuiting in JavaScript occurs when the logical operators '&&' and '||' evaluate only as much as necessary. With '&&', if the first operand is false, the second operand is not evaluated. With '||', if the first operand is true, the second operand is not evaluated.
1. The arithmetic operator '______' is used for exponentiation in JavaScript.
Ans. '**' (double asterisk)
2. The _______ operator in JavaScript is used to determine the type of a variable.
Ans. 'typeof'
3. The _______ operator in JavaScript is used to access a property or method of an object.
Ans. '.' (dot)
4. The _______ operator in JavaScript is used to check if a property exists in an object.
Ans. 'in'
5. The _______ operator in JavaScript is used to increment the value of a variable by 1.
Ans. '++'
1. The '+' operator can be used to concatenate both strings and numbers in JavaScript.
Ans. True
2. The '&&' operator in JavaScript always evaluates both operands.
Ans. False
3. The '!' operator in JavaScript is used to perform logical negation.
Ans. True
4. The '==' operator in JavaScript compares both value and type.
Ans. False
5. The '++' operator in JavaScript increments the value of a variable by 2.
Ans. False
Q.1. Write a JavaScript function that takes two numbers as parameters and returns their sum.
function sumNumbers(a, b) {
return a + b;
}
Q.2. Write a JavaScript program that prompts the user to enter a number and displays whether the number is even or odd.
let number = prompt("Enter a number:");
if (number % 2 === 0) {
console.log("The number is even.");
} else {
console.log("The number is odd.");
}
Q.3. Write a JavaScript function that checks if a given string is a palindrome (reads the same backward as forward). Return true if it is, false otherwise.
function isPalindrome(str) {
let reversedStr = str.split('').reverse().join('');
return str === reversedStr;
}
Q.4. Write a JavaScript program that calculates the factorial of a given number. The factorial of a number is the product of all positive integers less than or equal to the number.
function factorial(num) {
if (num === 0 || num === 1) {
return 1;
} else {
return num * factorial(num - 1);
}
}
Q.5. Write a JavaScript program that converts a temperature from Celsius to Fahrenheit. The formula to convert Celsius to Fahrenheit is: Fahrenheit = (Celsius * 9/5) + 32.
function celsiusToFahrenheit(celsius) {
return (celsius * 9/5) + 32;
}
51 videos|28 docs|12 tests
|
|
Explore Courses for Software Development exam
|