Every question now follows the same visual structure so readers can scan fast, understand quickly, and focus on the concept instead of fighting the layout.
4 questions available
Page 1 of 1
Showing 4 questions on this page
A variable in JavaScript is a container used to store data.
let name = "Alice"; // 'let' is block-scoped
const birthYear = 1990; // 'const' is block-scoped and cannot be reassigned
var city = "New York"; // 'var' is function-scoped (deprecated in modern JS)JavaScript has two main categories of data types:
let name = "John"; // String
let age = 30; // Number
let isAdult = true; // Boolean
let address = null; // Null
let salary; // Undefined
let uniqueID = Symbol("id"); // Symbol
let bigNumber = 9007199254740991n; // BigInt (add 'n' at the end for BigInt)
let person = { name: "John", age: 30 }; // Object
let colors = ['red', 'green', 'blue']; // Array
let greet = function() { return "Hello"; }; // Function"null" is a special value representing the absence of any value, while "undefined" means a variable has been declared but not assigned a value.
let address = null; // Null
let phoneNumber; // Undefined (not assigned a value)In JavaScript, `let`, `var`, and `const` are used for variable declarations, but they differ in their behavior:
var x = 10;
if (true) {
var x = 20; // Redeclares and updates the same variable
console.log(x); // Output: 20
}
console.log(x); // Output: 20
let y = 10;
if (true) {
let y = 20; // Creates a block-scoped variable
console.log(y); // Output: 20
}
console.log(y); // Output: 10
const z = 10;
if (true) {
const z = 20; // Creates a block-scoped variable
console.log(z); // Output: 20
}
console.log(z); // Output: 10
// Mutating objects with const
const person = { name: "John" };
person.name = "Doe"; // Allowed: Mutating the object
console.log(person.name); // Output: Doe
// Reassigning a const variable
// const person = {}; // Error: Cannot reassign a const variableKeep moving topic by topic. Consistency matters in interview prep.