100 JS Concepts
100 JS Concepts
1- Variables: Variables are containers for storing data values. There are three types of variables in
JavaScript: var, let, and const.
let x = 5; // x is 5
const pi = 3.14; // pi is a constant 3.14
2- Data Types: JavaScript has several data types including Number, String, Boolean, Object, Function,
Null, and Undefined.
4- Objects: Objects are variables too. But objects can contain many values.
6- Control Structures: Control structures help you handle the flow of your program. This includes if,
else, switch, for, while, do-while.
if (x > y) {
// do something
} else {
// do something else }
7- Functions: Functions are blocks of code that can be defined, then called at a later time, or in
response to an event.
function myFunction(x, y) {
return x * y;
}
8- Events: JavaScript's interaction with HTML is handled through events that occur when the user or
browser manipulates a page. html
9- Strings and String Methods: Strings are useful for holding data that can be represented in text
form. There are many methods that can be used with strings including length, indexOf, search, replace,
etc.
10- Number and Number Methods: JavaScript has only one type of number. Numbers can be written
with, or without decimals. JavaScript numbers can also include + and - , and e to indicate exponents.
12- JavaScript Math: JavaScript Math is a built-in object that has properties and methods for
mathematical constants and functions.
13- Boolean Logic: Boolean is a datatype that returns either of two values i.e., true or false.
let isCodingFun = true; let
isFishTasty = false;
14- Error Handling (try/catch/finally): JavaScript allows exception handling via the try, catch, and
finally blocks. try contains the code to be run, catch catches any errors, and finally runs code regardless of
an error occurring or not.
try {
notAFunction();
} catch(err) { console.log(err); // ReferenceError: notAFunction is not defined
} finally { console.log('This will run regardless of the try/catch result'); }
15- Regular Expressions: Regular expression is an object that describes a pattern of characters.
let patt = new RegExp("e"); let res = patt.test("The best things in life are
free!"); 16- JSON: JSON (JavaScript Object Notation) is a lightweight data
interchange format that is easy for humans to read and write, and easy for
machines to parse and generate.
17- AJAX: AJAX is about updating parts of a web page, without reloading the whole page. It stands for
Asynchronous JavaScript and XML.
21- Arrow Functions: Arrow functions allow for a shorter syntax when writing functions. Arrow
functions do not have their own this.
22- Template Literals: Template literals provide an easy way to interpolate variables and expressions
into strings.
23- Spread Operator and Rest Parameters: The spread operator allows an iterable to be expanded in
places where zero or more arguments are expected. The rest parameter syntax allows a function to
accept an indefinite number of arguments as an array.
// Spread operator let arr1 = [1, 2, 3]; let arr2 = [...arr1, 4, 5, 6];
// [1, 2, 3, 4, 5, 6]
24- Destructuring Assignment: The destructuring assignment syntax is a JavaScript expression that
makes it possible to unpack values from arrays, or properties from objects, into distinct variables.
25- Modules: JavaScript modules are a way to share and reuse code across files.
26- Classes and Inheritance: Classes are a template for creating objects. Inheritance is a way of creating
a new class using methods and properties of an existing class.
class Animal { constructor(name) {
this.name = name;
} speak() { console.log(this.name + ' makes a noise.'); }
}
27- Symbols: Symbols are a new primitive type in JavaScript. Every symbol value returned from Symbol()
is unique.
28- Iterators and Generators: Iterators are objects that know how to access items from a collection one
at a time, while keeping track of its current position within that sequence. Generators are a special
class of functions that simplify the task of writing iterators.
29- Map, Filter, and Reduce: map, filter, and reduce are all array methods in JavaScript that provide a
functional programming style.
let numbers = [1, 2, 3, 4]; let doubled = numbers.map(item => item *
2); let biggerThanTwo = numbers.filter(item => item > 2); let sum =
numbers.reduce((a, b) => a + b);
30- Set and Map: Both Set and Map are newer built-in objects in JavaScript. A Set object lets you store
unique values of any type, whether primitive values or object references. A Map object holds key-
value pairs and remembers the original insertion order of the keys.
31- NaN: NaN is a special value that stands for "Not a Number". It is used to indicate an undefined or
unrepresentable value.
console.log(Math.sqrt(-1)); // NaN
32- Null and Undefined: Both null and undefined are special values in JavaScript. undefined means a
variable has been declared but has not yet been assigned a value. null is an assignment value. It can
be assigned to a variable to represent no value or no object.
test = null;
console.log(test); // null
33- Truthy and Falsy: Every value in JavaScript has an inherent boolean value. When that value is
evaluated in the context of a boolean expression, we say that value is either truthy or falsy.
36- Scope and Hoisting: Scope is the accessibility or visibility of variables, functions, and objects in
some particular part of your code during runtime. Hoisting is a JavaScript mechanism where variables and
function declarations are moved to the top of their containing scope.
37- Immutability: In JavaScript, const doesn't create an immutable variable, but it does create a
variable that can't be reassigned. For arrays and objects, it means you can't reassign the entire object, but
you can mutate its properties.
39- Prototype and Inheritance: Prototypes are the mechanism by which JavaScript objects inherit
features from one another.
let animal = { eats: true
}; let rabbit = Object.create(animal);
console.log(rabbit.eats); // true
40- Web APIs: Web APIs provide the functionality to create a dynamic, interactive web application.
These APIs include DOM manipulation, Fetch API, Geolocation API, Web Storage, and more.
fetch('https://api.github.com/users/github')
.then(response => response.json())
.then(data => console.log(data));
41- this Keyword: this keyword refers to the object that is executing the current function.
42- Timeouts and Intervals: setTimeout function is used to schedule code execution after a designated
amount of milliseconds. setInterval is used to execute code repeatedly, starting after the interval of time,
then repeating continuously at that interval.
setTimeout(() => { console.log('Runs after 2
seconds');
}, 2000);
44- Local Storage: Local Storage allows you to access a local Storage object. Data stored persistently
and isn't sent with every server request.
localStorage.setItem('myKey', 'myValue'); let data =
localStorage.getItem('myKey'); console.log(data); //
'myValue'
45- Session Storage: Session Storage allows you to add, modify, or remove stored data which is saved
temporarily and gets deleted after the session ends (when the tab is closed).
46- Data Attributes: Data attributes let you assign custom data to an element.
47- Tagged Template Literals: Tagged templates allow you to parse template literals with a function.
let a = 5; let b =
10;
48- IIFE (Immediately Invoked Function Expression): An IIFE is a function that runs as soon as it is
defined.
49- Strict Mode: Strict mode makes several changes to normal JavaScript semantics. It eliminates some
JavaScript silent errors by changing them to throw errors.
'use strict'; x =
3.14; // This will cause an error because x is not defined
50- Array methods (some, every, find): some checks if some elements pass a test, every checks if all
elements pass a test, find returns the value of the first element that passes a test.
let greaterThanFour = array.some(num => num > 4); // true let allGreaterThanZero =
array.every(num => num > 0); // true let firstGreaterThanTwo = array.find(num => num > 2); //
3
51- Named function expressions: A named function expression is very similar to a function declaration,
except that it is created as a part of an expression.
52- JavaScript Encoding/Decoding: encodeURI and decodeURI functions are used to encode and
decode a URI.
53- Default parameters: Default function parameters allow named parameters to be initialized with
default values if no value or undefined is passed.
function multiply(a, b = 1) {
return a * b;
} console.log(multiply(5, 2)); // 10
console.log(multiply(5)); // 5
54- JavaScript Animation: JavaScript can be used to move elements around on the page, create a
slideshow, or other forms of animation.
let pos = 0;
let box = document.getElementById("animate");
55- JavaScript BOM (Browser Object Model): The BOM allows JavaScript to "talk to" the browser, it
includes objects like navigator, history, screen, location and document which is also the entry point into
the web page's content.
56- Web Workers: Web Workers are a simple means for web content to run scripts in background
threads.
57- Server Sent Events: Server-Sent Events (SSE) is a standard that allows a web page to get updates
from a server.
58- Fetch API: The Fetch API provides a JavaScript interface for accessing and manipulating HTTP
requests and responses.
fetch('https://api.github.com/users/github')
.then(response => response.json())
.then(data => console.log(data));
59- Object Property Shorthand: In situations where the key and the value that you're assigning to the
key in the object you're creating are the same, you can use a shorthand to create properties.
let name = 'John'; let age =
25;
61- WeakSet: The WeakSet object lets you store weakly held objects in a collection.
62- JavaScript Regular Expressions: A regular expression is a sequence of characters that forms a
search pattern. It's used for searching, extracting, and replacing text.
64- Reflect API: Provides methods for interceptable JavaScript operations. The methods are the same as
those of proxy handlers.
68- Optional chaining operator ?.: It allows to safely access nested objects without checking presence of
each of them.
69- Nullish coalescing operator ??: It returns the first argument if it’s not null/undefined. Otherwise, the
second one.
let height = 0;
console.log(height ?? 100); // 0
70- Loop labels: A label allows us to break/continue outer loops from a nested loop.
outer: for (let i = 0; i < 3; i++) {
for (let j = 0; j < 3; j++) {
let input = prompt(`Value at coords (${i},${j})`); if (!input) break outer; // if an empty line or
cancel, then break out of
both loops } }
console.log('Done!');
72- Shadow DOM: Encapsulates style and structure for web components.
this.handleClick = this.handleClick.bind(this);
74- GlobalThis: A universal way to access the global this value (aka global object) across environments.
75- Logical Assignment Operators: They perform a logical operation and assignment in one step.
76- Array at() method: Allows to get the element at a given index, with support for negative indices.
79- Pattern Matching Proposal: Allows to match and destructure data in a deeper, more expressive
way.
match (value) {
when ({ a: 1, b }) -> b
else -> throw new Error('not matched') }
80- Pipeline Operator Proposal: Allows to chain functions in a more readable, functional manner.
81- Currying: Currying is the process of converting a function with multiple arguments into a sequence
of functions, each taking a single argument.
82- Currying with lodash: The curry function from lodash can be used for currying.
const _ = require('lodash');
function multiply(a, b, c) {
return a * b * c;
}
83- Function composition: Function composition is combining multiple functions to form a new
function.
function add(a) {
return a + 1;
}
function multiply(b) {
return b * 2;
} var composedFunction = (x) => multiply(add(x));
console.log(composedFunction(3)); // Output: 8
84- Memoization: Memoization is a technique used to cache the results of expensive function calls to
improve performance.
if (n <= 2) { return 1;
}
85- Proxy traps: Proxy traps are the methods that can be defined on the handler object to customize the
behavior of the proxied object.
86- Function generators: Function generators are a combination of generators and functions, allowing
you to define reusable generator functions.
function* generateNumbers() {
let number = 0; while
(true) { yield number++;
} } const numberGenerator = generateNumbers();
console.log(numberGenerator.next().value); // Output: 0 console.log(numberGenerator.next().value); //
Output: 1
87- Private class fields: Private class fields are class fields that are scoped to the class and cannot be
accessed outside of it.
constructor(name) { this.#name =
name;
}
getName() { return
this.#name;
} } const person = new Person('John');
88- Optional chaining: Optional chaining allows you to access nested properties of an object without
worrying if any intermediate property is null or undefined.
89- Object spread syntax: Object spread syntax allows merging properties from multiple objects into a
new object.
const person = { name: 'John' }; const details = { age: 30, country: 'USA' }; const merged =
{ ...person, ...details }; console.log(merged); // Output: { name: 'John', age: 30, country: 'USA' }
90- Web Workers: Web Workers allow running JavaScript code in the background, off the main thread,
to improve performance and responsiveness.
91- Proxied built-in objects: You can create proxies for built-in objects like Array, Date, and Function to
intercept and customize their behavior.
92- Custom iterable objects: You can create custom iterable objects by implementing the iterator
protocol.
const iterable = { items: ['a', 'b',
'c'],
[Symbol.iterator]() { let index
= 0; return {
next: () => { if (index < this.items.length) { return { value: this.items[index+
+], done: false };
} return { done: true };
},
};
},
};
93- Decorators: Decorators allow adding functionality to classes, methods, and properties at design
time.
return descriptor;
}
class Calculator {
@log add(a, b)
{
return a + b;
}}
const calc = new Calculator(); console.log(calc.add(2, 3)); // Output: Calling add with arguments
2,3, 5
94- Throttling: Throttling is a technique to limit the number of times a function can be called within a
specific time frame.
function throttle(func, limit) { let inThrottle; return function (...args) {
if (!inThrottle) { func.apply(this, args); inThrottle = true;
setTimeout(() => (inThrottle = false), limit); }
}; }
95- Debouncing: Debouncing is a technique to delay the execution of a function until after a specific
amount of time has passed without the function being called again.
96- Object.freeze: The Object.freeze method freezes an object, making it immutable by preventing
adding, modifying, or deleting properties.
const obj = { name:
'John', age: 30,
};
Object.freeze(obj); obj.age = 40; // Assignment is ignored in strict mode or throws an error in non-
strict mode console.log(obj.age); // Output: 30
97- Object.seal: The Object.seal method seals an object, preventing the addition or deletion of
properties, but allowing the modification of existing properties.
99- FlatMap: The flatMap method combines the map and flat methods, allowing mapping each element
to a new array and then flattening the resulting arrays into a single array.
const result = numbers.flatMap((x) => [x, x * 2]); console.log(result); // Output: [1, 2, 2, 4, 3, 6] 100-
Object.fromEntries: The Object.fromEntries method transforms a list of key-value pairs into an
object.
const entries = [
['name', 'John'],
['age', 30],
];
const sentence = 'The quick brown fox jumps over the lazy dog.'; const newSentence =
sentence.replaceAll('the', 'a'); console.log(newSentence); // Output: The quick brown fox jumps
over a lazy dog.
102- Object.hasOwn: The hasOwn method checks if an object has a property directly defined on itself
(not inherited from the prototype chain).
105- File API: The File API provides a way to interact with files on the user's device using JavaScript.
const input = document.getElementById('fileInput');
reader.readAsText(file);
});
106- Intersection Observer API: The Intersection Observer API allows detecting when an element enters
or exits the viewport.