Interview Prep: Junior Level

Essential JavaScript interview questions for freshers and junior developers — fundamentals, syntax, and core concepts

Last updated on

These questions test your understanding of core JavaScript. Expect these in fresher and 0-2 year experience interviews.


Fundamentals

1. What are the data types in JavaScript?

7 primitives and Objects:

PrimitiveExample
String"hello"
Number42, 3.14
BigInt9007199254740991n
Booleantrue, false
Undefinedundefined
Nullnull
SymbolSymbol("id")

Objects include: {}, [], function(){}, Date, Map, Set, RegExp.

📖 Deep dive: Data Types


2. Difference between var, let, and const?

Featurevarletconst
ScopeFunctionBlockBlock
HoistingYes (as undefined)Yes (TDZ)Yes (TDZ)
Reassign
Redeclare

Rule: Use const by default, let when you need reassignment, never var.

📖 Deep dive: Variables


3. What is the difference between == and ===?

== converts types before comparing (type coercion). === compares both type AND value without conversion.

0 == ""      // true (both coerce to 0)
0 === ""     // false (number vs string)
null == undefined  // true (special case)
null === undefined // false

Always use === unless intentionally checking null == undefined.

📖 Deep dive: Type Coercion


4. What is hoisting?

JavaScript moves declarations to the top of their scope during the creation phase:

console.log(x);  // undefined (var is hoisted)
var x = 5;

console.log(y);  // ❌ ReferenceError (let is in TDZ)
let y = 10;

greet();          // ✅ works (function declarations are fully hoisted)
function greet() { console.log("hi"); }

📖 Deep dive: Hoisting


5. What is the difference between null and undefined?

  • undefined — variable declared but not assigned (JS sets this)
  • null — explicitly set to mean "no value" (developer sets this)
let x;
console.log(x);       // undefined
typeof undefined;      // "undefined"
typeof null;           // "object" (historic bug)

6. What are template literals?

Backtick strings that support interpolation and multi-line:

const name = "Shiva";
const msg = `Hello ${name}! 2+2 = ${2 + 2}`;

const html = `
  <div>
    <p>${msg}</p>
  </div>
`;

7. What is the difference between a function declaration and expression?

// Declaration — hoisted (can call before definition)
function greet() { return "hi"; }

// Expression — NOT hoisted
const greet = function() { return "hi"; };

// Arrow — NOT hoisted, no own `this`
const greet = () => "hi";

📖 Deep dive: Functions


8. What is an arrow function? How is it different?

FeatureNormal FunctionArrow Function
thisOwn (dynamic)Inherited (lexical)
argumentsYesNo
ConstructorYes (new)No
Syntaxfunction() {}() => {}
const obj = {
  name: "JS",
  // ❌ Arrow — `this` is NOT obj
  bad: () => console.log(this.name),
  // ✅ Normal — `this` IS obj
  good() { console.log(this.name); }
};

📖 Deep dive: Functions


9. What is typeof? What are the quirks?

typeof "hello"     // "string"
typeof 42          // "number"
typeof true        // "boolean"
typeof undefined   // "undefined"
typeof null        // "object" ← BUG (historic)
typeof []          // "object" ← use Array.isArray()
typeof function(){} // "function"
typeof NaN         // "number" ← NaN is technically a number

10. What are truthy and falsy values?

Falsy (6 values): false, 0, "", null, undefined, NaN

Everything else is truthy, including: "0", " ", [], {}, function(){}

if ([]) console.log("truthy!");  // ✅ runs — empty array is truthy!
if ("") console.log("nope");     // ❌ doesn't run — empty string is falsy

📖 Deep dive: Type Coercion


Core Concepts

11. What is scope?

Where variables are accessible. JavaScript has 4 types:

  1. Global — accessible everywhere
  2. Function — accessible only inside the function
  3. Blocklet/const inside { } (if, for, while)
  4. Module — scoped to the file (ES modules)

📖 Deep dive: Scope


12. What is a closure?

A function that remembers variables from its outer scope even after the outer function has returned.

function counter() {
  let count = 0;
  return () => ++count;
}

const inc = counter();
inc(); // 1
inc(); // 2
inc(); // 3

📖 Deep dive: Closures


13. Name the most used array methods.

MutatingNon-MutatingFunctional
push, popslicemap
shift, unshiftconcatfilter
spliceflatreduce
sort, reverseatfind, some, every

📖 Deep dive: Arrays


14. Difference between map, forEach, filter, and reduce?

MethodReturnsPurpose
forEachundefinedJust iterate (no return)
mapNew arrayTransform each element
filterNew arrayKeep elements that pass test
reduceSingle valueAccumulate to one result

15. How do you remove duplicates from an array?

const unique = [...new Set([1, 2, 2, 3, 3, 4])];
// [1, 2, 3, 4]

Guess the Output

Q1

console.log(1 + "2" + 3);
console.log(1 + 2 + "3");

Output: "123", "33"

1 + "2" → string concat "12""12" + 3"123". Second: 1 + 233 + "3""33".


Q2

console.log(typeof null);
console.log(typeof NaN);
console.log(NaN === NaN);

Output: "object", "number", false


Q3

var x = 10;
function test() {
  console.log(x);
  var x = 20;
}
test();

Output: undefined — inner var x is hoisted inside test(), shadowing outer x.


Q4

console.log([] == ![]);

Output: true![]false0, []""0, so 0 == 0.

📖 Deep dive: Type Coercion

On this page