What is a Variable? — JS Technical Interview Questions & Answers

Named storage for values, declared with var, let or const.

What is a Variable?

  • a Variable (js variables intro) is a JS topic. In plain words you use it for let total = 0 in a cart script. Don’t start with a slogan — start with that picture.
  • Smallest example: let for change, const for fixed. Type it, run it, and say what you see. If you can do that from memory, you know a Variable (js variables intro).
  • From the example next to this theory: Named storage for values, declared with var, let or const.
  • Trap: var leak / const reassign. Fix that before you talk about advanced JS.
  • Viva: what is a Variable (js variables intro)? Then show let for change, const for fixed. Then name the trap.

Technical Interview Tip: What is a Variable (js variables intro)? Show this: let for change, const for fixed. Trap: var leak / const reassign.

Code Examples for What is a Variable?

What is a Variable? — working example

let count = 1;          // number (primitive)
const label = "items";  // string
const active = true;    // boolean
let missing;            // undefined
const empty = null;

const a = [1, 2];
const b = a;            // reference copy
b.push(3);
console.log(a);         // [1, 2, 3]

console.log(Number("42"), String(7), Boolean(""));

What is a Variable? — primitives copy by value; objects/arrays copy by reference. Convert types explicitly with Number/String/Boolean.

How to Explain What is a Variable? to an Interviewer

What is a Variable (js variables intro)?

Used for let total = 0 a cart script Not just the heading

Give one small example of a Variable (js variables intro).

let for change, const for fixed Named storage for values, declared with var, let or const

What mistake do beginners make with a Variable (js variables intro)?

var leak / const reassign Show the fix

Where do you use a Variable (js variables intro)?

a cart script let total = 0