𝗝𝗮𝘃𝗮𝗦𝗰𝗿𝗶𝗽𝘁 𝗕𝗮𝘀𝗶𝗰𝘀: 𝗖𝗮𝗹𝗹𝗯𝗮𝗰𝗸𝘀, 𝗢𝗯𝗷𝗲𝗰𝘁𝘀, 𝗮𝗻𝗱 𝗘𝘅𝗲𝗰𝘂𝘁𝗶𝗼𝗻
JavaScript runs in two ways: synchronous and asynchronous.
Synchronous code runs line by line. The engine finishes one task before starting the next. This blocks the next task from running.
Asynchronous code allows tasks to run independently. You start a task and move to the next one while waiting. This improves performance in web apps.
Key asynchronous concepts: • Callbacks: Functions passed into other functions to run later. • Promises: Objects representing the result of an operation. • Async/Await: Modern syntax to make asynchronous code easy to read. • Event Loop: The system that manages task execution.
Understanding Processes and Threads
A process is a program in execution. • Processes are isolated. • They do not share memory. • A process can create child processes. • They take more time to terminate.
A thread is a segment of a process. • A process can have many threads. • Threads share memory. • They take less time to terminate.
What is a Callback Function?
A callback is a function passed as an argument. The outer function calls it to finish a task. Use callbacks for: • Asynchronous tasks like fetching data. • Event handling like button clicks. • Creating reusable code.
JavaScript Objects
An object stores data in key-value pairs. Keys identify values. Values can be primitives, other objects, or functions.
You can create objects in two ways:
Object Literals: Use curly braces to define properties. Example: let user = {name: "Sourav", age: 23};
Object Constructor: Use the new Object() command. Example: let user = new Object();
Objects are mutable. You can add, change, or delete properties at any time. This helps you group related data together.