JS Basic Tutorial
JS Basic Dom
JS Reference
var, let, and const in JavaScript?var: Function-scoped, can be redeclared and updated, hoisted but not initialized.let: Block-scoped, can be updated but not redeclared in the same scope, hoisted but not initialized.const: Block-scoped, cannot be updated or redeclared, must be initialized during declaration.Try it yourself
The event loop is a fundamental concept in JavaScript that allows asynchronous operations to be executed without blocking the main thread. JavaScript is single-threaded, meaning it executes code one line at a time. The event loop helps manage asynchronous tasks like:
Even though setTimeout is 0ms, it goes to Web APIs and runs after the synchronous code.
Promises run before setTimeout because microtasks (Promises) have higher priority than macrotasks (setTimeout).
Fetch works asynchronously, so JavaScript continues execution and logs "Other synchronous tasks..." before receiving API data.
== and === in JavaScript?== (Abstract Equality): Checks only values, allowing type coercion (e.g., 5 == "5" is true).=== (Strict Equality): Checks both values and types (e.g., 5 === "5" is false).this keyword work in JavaScript? The value of this depends on the execution context:
this refers to the window object (in browsers).this refers to the object calling the method.this refers to undefined in strict mode, else window.this is lexically inherited from the surrounding scope.bind(), call(), apply(): this can be explicitly set.Here, this refers to user.
this refers to the new object (p1).
Why? Arrow functions don’t bind this, they inherit it from their parent scope (which is window in this case).
Here, this refers to the element that triggered the event.
call, apply, bindcall()explicitly sets this to person.
Similar to call(), but apply() takes an array of arguments.
bind()returns a new function with this set to user.
call, apply, and bind?call(obj, arg1, arg2, …) → Calls function with this set to obj, arguments passed separately.apply(obj, [arg1, arg2, …]) → Similar to call(), but arguments are passed as an array.bind(obj) → Returns a new function with this permanently set to obj.A closure is a function that retains access to its parent scope even after the parent function has finished executing.
Here, innerFunction still has access to count even after outerFunction has returned.
map(), filter(), and reduce()?Answer:
map(): Transforms each array element and returns a new array.filter(): Returns a new array with elements that satisfy a condition.reduce(): Reduces the array to a single value (e.g., sum, product).async and await in JavaScript. async and await simplify working with promises by making asynchronous code look synchronous.
async makes a function return a promise.await pauses execution until the promise resolves.JavaScript uses Garbage Collection (GC) to free up memory that is no longer accessible.