JavaScript Features Interview Questions and Answers
Understand JavaScript's core characteristics, runtime behavior, compatibility, and the language features that distinguish it.
Frequently Asked Questions
Important questions are highlighted in the sections below; select one to jump to its answer.
- What does it mean for functions to be first-class values?
- What does prototype-based inheritance provide?
- Why are objects central to JavaScript programs?
- What is type coercion in JavaScript?
- Explain what it means for JavaScript to be single-threaded. What are the implications of this for concurrency and performance in web applications?
- What happens when we use the this keyword in strict mode?
- What happens to "this" in strict mode?
Theoretical JavaScript Interview Questions
Do not try to list every JavaScript feature. A strong answer names the characteristics that explain how JavaScript behaves: it is high-level, dynamically typed, garbage-collected, prototype-based, multi-paradigm, and single-threaded with an event loop that coordinates asynchronous work.
- High-Level Language: You write readable code, not raw machine instructions.
- Garbage Collected: Memory is cleaned up automatically - no manual free() calls.
- Interpreted and JIT-compiled: Engines parse JavaScript and may compile frequently executed code at runtime. The exact strategy varies by engine.
- Multi-Paradigm: You can write OOP, functional, or procedural code - your choice.
- Prototype-Based: Objects inherit through prototype chains. The
classsyntax provides class-style semantics on top of that model. - First-Class Functions: Functions are values - assign them to variables, pass them around, return them.
- Dynamically Typed: Variables can hold any type, and types are checked at runtime, not compile time.
- Single-threaded execution by default: A JavaScript agent normally runs one piece of JavaScript at a time on its main thread, while workers can run code on other threads.
- Event-loop concurrency: Timers and network APIs let the host schedule work without blocking while JavaScript is waiting, but CPU-heavy JavaScript still blocks its thread.
- Platform Independent: Runs in any browser, on any OS with Node.js, and even on IoT devices.
JavaScript is dynamically typed . You don't declare types when creating variables - JavaScript figures out the type at runtime. A variable can hold a string one moment and a number the next. This gives you flexibility but can cause sneaky bugs. That's exactly why TypeScript (which adds static types on top of JavaScript) has become so popular.
Interpreted describes a traditional execution model in which source is translated as the program runs. Compiled languages often translate a program before it runs, although the boundary is not absolute. Modern JavaScript engines parse source, produce an executable representation, and may use Just-In-Time (JIT) compilation to optimize frequently executed code. It is therefore more accurate to describe JavaScript engines by their execution pipeline than to label JavaScript simply "interpreted" or "compiled."
With JavaScript's
dynamic typing
, you never declare types - a variable can hold a
string, then a number, then an object. The engine
figures out types at runtime. In statically typed
languages like Java or TypeScript, you declare types
upfront and the compiler catches mismatches before your
code runs. JavaScript's approach means faster
prototyping but more runtime surprises. Classic
gotcha: "5" + 3 gives "53"
(string concatenation), while "5" - 3
gives 2 (numeric subtraction). That's
dynamic typing in action.
JavaScript's single-threaded nature means it has one call stack and executes one piece of code at a time. If a function takes 5 seconds to compute, everything else waits - the UI freezes, clicks don't register, animations stall. That's why JavaScript relies on asynchronous patterns: the event loop, callbacks, Promises, and async/await let you offload slow operations (network requests, timers) so the main thread stays responsive. For truly CPU-heavy work, Web Workers give you separate threads that run in the background without blocking the page.
JavaScript's platform independence means that the language can be implemented across operating systems, but the host APIs are not identical. The same language can run in Chrome, Safari, Node.js, or a mobile framework, while DOM, filesystem, networking, and security APIs differ. Portable code still needs compatible APIs, feature detection, or a build step for some targets.
Just-In-Time (JIT) compilation means code is compiled at runtime, just before execution. This gives JavaScript near-native performance: the engine optimizes hot code paths on the fly, reduces memory waste with dead code elimination, and adapts to actual runtime behavior.
In non-strict (sloppy) mode, JavaScript silently swallows a lot of mistakes - assigning to undeclared variables creates accidental globals, writing to read-only properties fails silently, and octal literals can cause confusion. These 'helpful' behaviors are actually traps. Always use 'use strict' at the top of your files, or just use ES modules which are strict by default.
In strict mode, this is undefined inside a plain function call instead of defaulting to the global object. This is actually the safer behavior - before strict mode, accidentally calling a method without an object context would silently mutate global state, which is a nasty bug to track down. Strict mode makes these mistakes throw errors immediately. Arrow functions are unaffected since they don't have their own this regardless of the mode.
In strict mode, when a regular function is called without any object context (just as a plain function call), this is undefined instead of the global object. This catches a lot of accidental bugs where you thought you were working with an object but you were actually modifying the global scope.
"use strict";
function show() {
console.log(this); // undefined, not window
}
show();
A JavaScript variable can hold values of different types at different times; the type belongs to the value rather than being fixed by the variable declaration. TypeScript can add static checks during development, but ordinary JavaScript is dynamically typed.
Functions can be assigned to variables, passed as arguments, returned from other functions, and stored in data structures. This enables callbacks and higher-order functions.
Objects can inherit behavior from other objects through a prototype chain. JavaScript class syntax builds on this prototype-based mechanism.
Type coercion is the conversion of a value from one type to another, performed explicitly by code or implicitly by an operation. Explicit conversion is often clearer when a conversion is intended.
Objects group properties and behavior under one value and can represent records, collections, and instances. Arrays and functions are also specialized kinds of objects.
The runtime can reclaim memory for objects that are no longer reachable from program roots, though the exact collection strategy is implementation-dependent. Keeping unnecessary references can prevent otherwise unused objects from being reclaimed.