๐ JavaScript Interview Questions with Answers โ Part 11. What is JavaScript?JavaScript is a high-level, interpreted programming language used to create interactive and dynamic web pages. It runs in web browsers and can also be used for backend development with Node.js.
Common Uses:
Interactive websites
Form validation
Animations
API calls
Web applications
Backend development
Example:
console.log("Hello JavaScript");2. What are the different data types in JavaScript?JavaScript has two categories of data types.
Primitive Data TypesString
Number
Boolean
Undefined
Null
BigInt
Symbol
Non-Primitive (Reference) Data TypesObject
Array
Function
Example:
let name = "Deepak"; // String
let age = 25; // Number
let isActive = true; // Boolean
let data = null; // Null
let value; // Undefined
3. What is the difference between var, let, and const?Feature | var | let | const
Scope | Function | Block | Block
Reassign | โ
Yes | โ
Yes | โ No
Redeclare | โ
Yes | โ No | โ No
Hoisted | โ
Yes | โ
Yes (TDZ) | โ
Yes (TDZ)
Example:
var a = 10;
let b = 20;
const c = 30;
Interview Tip:
Use const by default, let when the value changes, and avoid var in modern JavaScript.
4. What are primitive and non-primitive data types?Primitive Data TypesStored by value.
Examples:
String
Number
Boolean
Null
Undefined
BigInt
Symbol
Non-Primitive Data TypesStored by reference.
Examples:
Objects
Arrays
Functions
Example:
let a = 10;
let b = a;
b = 20;
console.log(a); // 10
Reference Example:
const obj1 = { name: "John" };
const obj2 = obj1;
obj2.name = "Mike";
console.log(obj1.name); // Mike5. What is type coercion?Type coercion is JavaScript's automatic conversion of one data type into another during operations or comparisons.
Example:
console.log("5" + 2); // "52"
console.log("5" - 2); // 3Types:
Implicit coercion (automatic)
Explicit coercion (manual)
Explicit Example:
Number("10"); // 10
String(100); // "100"6. What is the difference between == and ===?== (Loose Equality)Compares values only
Performs type conversion
=== (Strict Equality)Compares both value and data type
No type conversion
Example:
console.log(5 == "5"); // true
console.log(5 === "5"); // false
Best Practice:
Always prefer === to avoid unexpected results.
7. What are truthy and falsy values?Truthy ValuesValues treated as true in a boolean context.
Examples:
Non-empty strings
Non-zero numbers
Objects
Arrays
Falsy ValuesJavaScript has these falsy values:
false
0
-0
0n
"" (empty string)
null
undefined
NaN
Example:
if ("Hello") {
console.log("Truthy");
}
if (0) {
console.log("Won't execute");
}8. What is undefined?undefined means a variable has been declared but has not been assigned a value.
Example:
let value;
console.log(value);
Output:
undefinedKey Point:
undefined is assigned automatically by JavaScript.
9. What is null?null represents an intentional absence of any object value.
It is assigned manually by the developer.
Example:
let user = null;
console.log(user);
Output:
nullDifference:
undefined โ No value assigned.
null โ Empty value assigned intentionally.
10. What is NaN?NaN stands for Not a Number.
It represents an invalid numeric result.
Claim your Free $5 Bonus Here:https://bit.ly/3wUxw09LinkedIn profile ๐https://www.linkedin.com/in/subarno-roy-3b22513741๏ธโฃ
Artificial Intelligence๐ Channel Link:
[
https://t.me/artificialintelligence_official ]
2๏ธโฃ
Programming Books๐ Channel Link:
[
https://t.me/programmingbooksofficial ]
3๏ธโฃ
Android Development๐ Channel Link:
[
https://t.me/androiddevelopmentofficial ]
4๏ธโฃ
App Development๐ Channel Link:
[
https://t.me/appdevelopmentofficial ]
5๏ธโฃ Ethical Hacking๐ Channel Link:
[
https://t.me/ethicalhacking_official ]