JavaScript Core Concepts
JavaScript Core Concepts
Key Features:
Common Uses:
1.2 Expressions
A piece of code that produces a value.
Examples:
5+5 // 10 (arithmetic)
1.4 Classes
Blueprint for creating objects using the class keyword.
class Person {
constructor(name) {
this.name = name;
greet() {
1.5 Variables
var x = 10;
let y = 20;
const z = 30;
1.6 Functions
Reusable blocks of code.
Function Declaration vs Expression:
Also supports:
const person = {
name: "Alice",
greet: function() {
console.log(this.name); // "Alice"
};
person.greet();
1.9 Loops
Used to execute code repeatedly.
1.10 Scopes
if (true) {
console.log(y); // 20
console.log(x); // Error
1.11 Arrays
Ordered lists with powerful methods:
nums.push(4); // [1, 2, 3, 4]
2. Asynchronous Programming
2.1 Callbacks
A function passed to another function to be executed later.
function fetchData(callback) {
2.2 Timers
2.3 Promises
An object representing the eventual result of an async operation.
States: pending, fulfilled, rejected.
});
Also supports:
• Promise.all()
• Promise.race()
return data;
3.1 Closures
A closure is a function that remembers variables from its outer scope even after the
outer function has returned.
function outer() {
let x = 10;
function inner() {
console.log(x); // Remembers x
return inner;
closureFn(); // 10
console.log("Start");
console.log("End");
Basics
1️⃣ What are the different data types in JavaScript?
• JavaScript moves declarations (not initializations) to the top of the scope. var is hoisted
with undefined; let and const are hoisted but not initialized.
• A function that remembers variables from its outer scope even after the outer function
has finished executing.
• It handles asynchronous code by moving tasks from the callback queue or microtask
queue to the call stack when it is empty.
• Strings wrapped in backticks (``) that allow embedded expressions using ${}.
• Shorter syntax for functions that do not have their own this binding.
• Transforming a function with multiple arguments into a sequence of functions with one
argument
• Objects can inherit properties/methods from another object via prototype chain
• Syntactic sugar over Promises, allows writing async code like synchronous
Advanced Concepts
• Design pattern that encapsulates code using closures and returns public APIs
• Technique of using a single event listener on a parent to handle events from its children