JavaScript Question Bank - Answer Sheet
1. List any four features of JavaScript.
- Lightweight and interpreted.
- Object-oriented.
- Event-driven.
- Platform-independent.
- Supports asynchronous programming.
2. List & explain datatypes in JavaScript.
- Primitive: String, Number, Boolean, Null, Undefined, Symbol, BigInt.
- Non-Primitive: Object, Array, Function, Date, RegExp.
3. Write a JavaScript program to check whether entered number is prime or not.
function isPrime(num) {
if (num <= 1) return false;
for (let i = 2; i <= Math.sqrt(num); i++) {
if (num % i === 0) return false;
}
return true;
}
console.log(isPrime(7)); // true
4. Difference between == and === operators.
- == : Compares value only (type coercion).
- === : Compares value and type (strict equality).
5. Difference between var and let keyword in JavaScript.
- var: function-scoped, hoisted, allows redeclaration.
- let: block-scoped, no redeclaration in same scope.
6. Explain implicit type coercion in JavaScript.
Automatic conversion of values from one type to another (e.g., '5' + 2 = '52').
7. What is NaN property in JavaScript?
NaN means 'Not-a-Number'. It’s returned from invalid math operations (e.g., 0/0).
8. Output of given code.
40
30
9. Output of given code.
10
5
10. Which keyword is used to declare a variable that cannot be reassigned?
const
11. Output of given code.
Hello5
12. Output of given code.
undefined
13. Output of given code.
105
14. Output of ternary operation.
Yes
15. Output of given code.
true