Table of contents | |
Instructions | |
MCQs (Multiple Choice Questions) | |
HOTS (Higher Order Thinking Questions) | |
Fill in the Blanks | |
True or False | |
Hands-On Questions |
Q.1. Which of the following is not a valid data type in JavaScript?
(a) Number
(b) Boolean
(c) String
(d) Character
Ans. (d)
Q.2. What is the correct way to declare a variable in JavaScript?
(a) var = myVar;
(b) myVar;
(c) var myVar;
(d) variable myVar;
Ans. (c)
Q.3. What is the purpose of the "if" statement in JavaScript?
(a) To declare a function
(b) To loop through an array
(c) To execute code based on a condition
(d) To define a class
Ans. (c)
Q.4. Which of the following is used to display a message in the browser's console?
(a) alert()
(b) console.log()
(c) prompt()
(d) document.write()
Ans. (b)
Q.5. What is the output of the following code snippet?
var x = 10;
var y = "5";
var z = x + y;
console.log(z);
(a) 15
(b) 105
(c) "105"
(d) Error
Ans. (c)
Q.1. Explain the difference between "==" and "===" operators in JavaScript.
The "==" operator compares values, allowing type coercion, while the "===" operator compares values and types, without type coercion. For example, "5" == 5 would return true, but "5" === 5 would return false.
Q.2. How can you check if a variable is an array in JavaScript?
You can use the "Array.isArray()" method to check if a variable is an array in JavaScript. For example:
var arr = [1, 2, 3];
console.log(Array.isArray(arr)); // Output: true
Q.3. What are the differences between the "let", "const", and "var" keywords in JavaScript?
- The "var" keyword is used to declare variables with function scope. It can be redeclared and reassigned.
- The "let" keyword is used to declare block-scoped variables. It can be reassigned but not redeclared within the same scope.
- The "const" keyword is used to declare block-scoped variables that cannot be reassigned or redeclared within the same scope.
Q.4. What is the purpose of the "typeof" operator in JavaScript? Provide an example.
The "typeof" operator is used to determine the type of a value or variable in JavaScript. For example:
var num = 10;
console.log(typeof num); // Output: "number"
Q.5. Explain the concept of hoisting in JavaScript.
Hoisting is a JavaScript mechanism where variable and function declarations are moved to the top of their respective scopes during the compilation phase, allowing them to be used before they are declared in the code. However, only the declarations are hoisted, not the initializations.
1. JavaScript is a ____________-side programming language.
Ans. client-side
2. The document object represents the ____________ of the current HTML document.
Ans. structure
3. The ____________ method in JavaScript is used to convert a string to uppercase.
Ans. toUpperCase()
4. JavaScript uses ____________ as the arithmetic operator for exponentiation.
Ans. "**"
5. The ____________ method in JavaScript is used to remove the last element from an array.
Ans. pop()
1. JavaScript is a case-sensitive language. (True/False)
Ans. True
2. The "for" loop is used to execute a block of code a specific number of times. (True/False)
Ans. True
3. JavaScript is a strictly typed language. (True/False)
Ans. False
4. The "NaN" value represents "Not a Number" in JavaScript. (True/False)
Ans. True
5. JavaScript supports automatic garbage collection. (True/False)
Ans. True
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 function to find the maximum element in an array.
function findMaxElement(arr) {
return Math.max(...arr);
}
Q.3. Write a JavaScript function to reverse a string.
function reverseString(str) {
return str.split("").reverse().join("");
}
Q.4. Write a JavaScript program to check if a given number is prime.
function isPrime(number) {
if (number <= 1) {
return false;
}
for (let i = 2; i <= Math.sqrt(number); i++) {
if (number % i === 0) {
return false;
}
}
return true;
}
Q.5. Write a JavaScript program to print the Fibonacci series up to a given number.
function fibonacciSeries(n) {
const series = [0, 1];
for (let i = 2; i <= n; i++) {
const nextNumber = series[i - 1] + series[i - 2];
if (nextNumber <= n) {
series.push(nextNumber);
} else {
break;
}
}
return series;
}
51 videos|28 docs|12 tests
|
|
Explore Courses for Software Development exam
|