In a Javascript L1 & L2 round the following questions can be asked from interviewer. 1. What is the difference between 'Pass by Value' and 'Pass by Reference'? 2. What is the difference between map and filter ? 3. What is the difference between map() and forEach() 4. What is the difference between Pure and Impure functions? 5. What is the difference between for-in and for-of ? 6. What are the differences between call(), apply() and bind() ? 7. List out some key features of ES6 ? 8. What’s the spread operator in javascript ? 9. What is rest operator in javascript ? 10. What are DRY, KISS, YAGNI, SOLID Principles ? 11. What is temporal dead zone ? 12. Different ways to create object in javascript ? 13. Whats the difference between Object.keys,values and entries 14. Whats the difference between Object.freeze() vs Object.seal() 15. What is a polyfill in javascript ? 16. What is generator function in javascript ? 17. What is prototype in javascript ? 18. What is IIFE ? 19. What is CORS ? 20. What are the different datatypes in javascript ? 21. What are the difference between typescript and javascript ? 22. What is authentication vs authorization ? 23. Difference between null and undefined ? 24. What is the output of 3+2+”7” ? 25. Slice vs Splice in javascript ? 26. What is destructuring ? 27. What is setTimeOut in javascript ? 28. What is setInterval in javascript ? 29. What are Promises in javascript ? 30. What is a callstack in javascript ? 31. What is a closure ? 32. What are callbacks in javascript ? 33. What are Higher Order Functions in javascript ? 34. What is the difference between == and === in javascript ? 35. Is javascript a dynamically typed language or a statically typed language 36. What is the difference between Indexeddb and sessionstorage ? 37. What are Interceptors ? 38. What is Hoisting ? 39. What are the differences let, var and const ? 41. Differences between Promise.all, allSettled, any, race ? 42. What are limitations of arrow functions? 43. What is difference between find vs findIndex ? 44. What is tree shaking in javascrip 45. What is the main difference between Local Storage and Session storage 46. What is eval() 47. What is the difference between Shallow copy and deep copy 48. What are the difference between undeclared and undefined variables 49. What is event bubbling 50. What is event capturing 51. What are cookies 52. typeOf operator 53. What is this in javascript and How it behaves in various scenarios 54. How do you optimize the performance of application 55. What is meant by debouncing and throttling #js #javascript #react #next #v8
Javascript Interview Questions and Answers
More Relevant Posts
-
In a Javascript L1 & L2 round the following questions can be asked from interviewer. 1. What is the difference between 'Pass by Value' and 'Pass by Reference'? 2. What is the difference between map and filter ? 3. What is the difference between map() and forEach() 4. What is the difference between Pure and Impure functions? 5. What is the difference between for-in and for-of ? 6. What are the differences between call(), apply() and bind() ? 7. List out some key features of ES6 ? 8. What’s the spread operator in javascript ? 9. What is rest operator in javascript ? 10. What are DRY, KISS, YAGNI, SOLID Principles ? 11. What is temporal dead zone ? 12. Different ways to create object in javascript ? 13. Whats the difference between Object.keys,values and entries 14. Whats the difference between Object.freeze() vs Object.seal() 15. What is a polyfill in javascript ? 16. What is generator function in javascript ? 17. What is prototype in javascript ? 18. What is IIFE ? 19. What is CORS ? 20. What are the different datatypes in javascript ? 21. What are the difference between typescript and javascript ? 22. What is authentication vs authorization ? 23. Difference between null and undefined ? 24. What is the output of 3+2+”7” ? 25. Slice vs Splice in javascript ? 26. What is destructuring ? 27. What is setTimeOut in javascript ? 28. What is setInterval in javascript ? 29. What are Promises in javascript ? 30. What is a callstack in javascript ? 31. What is a closure ? 32. What are callbacks in javascript ? 33. What are Higher Order Functions in javascript ? 34. What is the difference between == and === in javascript ? 35. Is javascript a dynamically typed language or a statically typed language 36. What is the difference between Indexeddb and sessionstorage ? 37. What are Interceptors ? 38. What is Hoisting ? 39. What are the differences let, var and const ? 41. Differences between Promise.all, allSettled, any, race ? 42. What are limitations of arrow functions? 43. What is difference between find vs findIndex ? 44. What is tree shaking in javascrip 45. What is the main difference between Local Storage and Session storage 46. What is eval() 47. What is the difference between Shallow copy and deep copy 48. What are the difference between undeclared and undefined variables 49. What is event bubbling 50. What is event capturing 51. What are cookies 52. typeOf operator 53. What is this in javascript and How it behaves in various scenarios 54. How do you optimize the performance of application 55. What is meant by debouncing and throttling 𝐠𝐞𝐭 𝐞𝐛𝐨𝐨𝐤 𝐰𝐢𝐭𝐡 (detailed 232 ques = 90+ frequently asked Javascript interview questions and answers, 90+ Reactjs Frequent Ques & Answers, 50+ Output based ques & ans, 23+ Coding Questions & ans, 2 Machine coding ques & ans) 𝐄𝐛𝐨𝐨𝐤 𝐋𝐢𝐧𝐤: https://lnkd.in/gJMmH-PF Follow on Instagram : https://lnkd.in/gXTrcaKP #javascriptdeveloper #reactjs #reactnative #vuejsdeveloper #angular #angulardeveloper
To view or add a comment, sign in
-
In a Javascript L1 & L2 round the following questions can be asked from interviewer. 1. What is the difference between 'Pass by Value' and 'Pass by Reference'? 2. What is the difference between map and filter ? 3. What is the difference between map() and forEach() 4. What is the difference between Pure and Impure functions? 5. What is the difference between for-in and for-of ? 6. What are the differences between call(), apply() and bind() ? 7. List out some key features of ES6 ? 8. What’s the spread operator in javascript ? 9. What is rest operator in javascript ? 10. What are DRY, KISS, YAGNI, SOLID Principles ? 11. What is temporal dead zone ? 12. Different ways to create object in javascript ? 13. Whats the difference between Object.keys,values and entries 14. Whats the difference between Object.freeze() vs Object.seal() 15. What is a polyfill in javascript ? 16. What is generator function in javascript ? 17. What is prototype in javascript ? 18. What is IIFE ? 19. What is CORS ? 20. What are the different datatypes in javascript ? 21. What are the difference between typescript and javascript ? 22. What is authentication vs authorization ? 23. Difference between null and undefined ? 24. What is the output of 3+2+”7” ? 25. Slice vs Splice in javascript ? 26. What is destructuring ? 27. What is setTimeOut in javascript ? 28. What is setInterval in javascript ? 29. What are Promises in javascript ? 30. What is a callstack in javascript ? 31. What is a closure ? 32. What are callbacks in javascript ? 33. What are Higher Order Functions in javascript ? 34. What is the difference between == and === in javascript ? 35. Is javascript a dynamically typed language or a statically typed language 36. What is the difference between Indexeddb and sessionstorage ? 37. What are Interceptors ? 38. What is Hoisting ? 39. What are the differences let, var and const ? 41. Differences between Promise.all, allSettled, any, race ? 42. What are limitations of arrow functions? 43. What is difference between find vs findIndex ? 44. What is tree shaking in javascrip 45. What is the main difference between Local Storage and Session storage 46. What is eval() 47. What is the difference between Shallow copy and deep copy 48. What are the difference between undeclared and undefined variables 49. What is event bubbling 50. What is event capturing 51. What are cookies 52. typeOf operator 53. What is this in javascript and How it behaves in various scenarios 54. How do you optimize the performance of application 55. What is meant by debouncing and throttling 𝐠𝐞𝐭 𝐞𝐛𝐨𝐨𝐤 𝐰𝐢𝐭𝐡 (detailed 232 ques = 90+ frequently asked Javascript interview questions and answers, 90+ Reactjs Frequent Ques & Answers, 50+ Output based ques & ans, 23+ Coding Questions & ans, 2 Machine coding ques & ans) 𝐄𝐛𝐨𝐨𝐤 𝐋𝐢𝐧𝐤: https://lnkd.in/gJMmH-PF Follow on Instagram : https://lnkd.in/gXTrcaKP #javascriptdeveloper #reactjs #reactnative #vuejsdeveloper #angular #angulardeveloper
To view or add a comment, sign in
-
So you want to write cleaner code in JavaScript - it's a game changer. Functional composition is key to achieving this, and it's actually pretty simple: you combine multiple functions into one. It's like building with Legos, you start with small pieces and create something complex. Here's the basic idea: you define a function that takes multiple functions as arguments, and it returns a new function that applies the original functions in a specific order - think of it like a recipe. You can use this concept to create new functions, like a master chef combining ingredients to create a new dish. For example, you can create a function that adds 2 to a number, then multiplies it by 3 - it's like a math puzzle. It looks something like this: ```javascript const compose = (...functions) => (x) => functions.reduceRight((acc, fn) => fn(acc), x); ``` And you can use it like this: ```javascript const add2 = (num) => num + 2; const multiply3 = (num) => num * 3; const add2ThenMultiply3 = compose(multiply3, add2); console.log(add2ThenMultiply3(5)); // Output: 21 ``` It's pretty cool. Functional composition also works with asynchronous functions - it's like a symphony, where each function plays its part at the right time. You can create a function that composes asynchronous functions, like this: ```javascript const asyncCompose = (...fns) => (initialInput) => fns.reduceRight( (promise, fn) => promise.then(fn), Promise.resolve(initialInput) ); ``` And use it like this: ```javascript const fetchData = (id) => new Promise((resolve) => { setTimeout(() => resolve(`Data for ${id}`), 1000); }); const transformData = (data) => `${data} transformed!`; const composedAsyncFunction = asyncCompose(transformData, fetchData); composedAsyncFunction(1).then(console.log); // Output after 1 second: "Data for 1 transformed!" ``` Now, to take it to the next level, you can use techniques like batching function calls and memoization - it's like optimizing a car engine, you get more power and efficiency. Memoization is like caching, you store the results of expensive function calls so you don't have to repeat them - it's a huge performance boost. You can create a memoize function like this: ```javascript const memoize = (fn) => { const cache = {}; return function (...args) { const key = JSON.stringify(args); if (!(key in cache)) { cache[key] = fn(...args); } return cache[key]; }; }; ``` It's a powerful tool. By using functional composition and these techniques, you can write more efficient and maintainable code in JavaScript - it's a total win. Check out this article for more info: https://lnkd.in/g3-F4DKC #javascript #functionalprogramming #codingtips
To view or add a comment, sign in
-
🚀 Master JavaScript Like a Pro: call(), apply() & bind() Explained Simply Most developers use JavaScript every day… But very few truly understand how this actually works. If call(), apply(), and bind() ever confused you — this post will make it click 👇 🔹 Why Do We Even Need These? In JavaScript, functions don’t own this — 👉 the execution context decides its value. That’s why sometimes this behaves unexpectedly. To control it, JavaScript gives us: call(), apply(), and bind() 1️⃣ call() — Execute Immediately with a Custom Context Use call() when you want to invoke a function right away and explicitly decide what this refers to. function greet(city) { console.log(`Hello, I am ${this.name} from ${city}`); } const user = { name: "Alex" }; greet.call(user, "Berlin"); ✔ Executes immediately ✔ Arguments passed one by one ✔ Commonly used for function borrowing 2️⃣ apply() — Same Power, Different Input Style apply() works just like call(), but it accepts arguments as an array. function introduce(role, company) { console.log(`${this.name} works as a ${role} at ${company}`); } const user = { name: "Jordan" }; introduce.apply(user, ["Developer", "TechNova"]); ✔ Same behavior as call() ✔ Useful when arguments come as an array 3️⃣ bind() — Create a Reusable Function bind() doesn’t execute the function immediately. Instead, it returns a new function with this permanently bound. function greet() { console.log(`Hello, ${this.name}`); } const user = { name: "Taylor" }; const greetUser = greet.bind(user); greetUser(); ✔ Perfect for event handlers ✔ Prevents context loss ✔ Extremely useful in async code 🔑 Key Takeaway If JavaScript ever felt unpredictable, this is usually why. ✔ call() → run now ✔ apply() → run now with array arguments ✔ bind() → run later with fixed context Mastering these gives you full control over execution context. 💬 Comment “JS” if you want the next post on Closures & Lexical Scope 🔖 Save this — you’ll come back to it. #JavaScript #FrontendDevelopment #WebDevelopment #CodingTips #LearnJS #DeveloperLife #Programming
To view or add a comment, sign in
-
-
Definition of common errors in #JavaScript 1. #SyntaxError: A #syntaxError in JavaScript (also known as a parsing error) occurs when the code violates the language's grammatical rules. The JavaScript engine throws a #SyntaxError when it attempts to interpret code with invalid structure, such as a missing parenthesis or a misspelled keyword. Unlike logic errors (which give the wrong output) or runtime errors (which happen during execution), a syntax error prevents the script from running at all because the interpreter cannot parse the code correctly. It is similar to a grammatical error in human language. 2. #ReferenceError: A #referenceError in JavaScript occurs when your code attempts to access a variable, function, or object that does not exist or has not been initialized in the current scope. It essentially means the JavaScript interpreter cannot find a valid reference to the item you are trying to use. 3. #TypeError: A #TypeError in JavaScript is an error that occurs when an operation cannot be performed because a value is not of the expected or valid data type for that operation. It indicates that while a variable might exist, it's being used in an inappropriate way given its type. 4. #RangeError: A #RangeError in JavaScript indicates that a value is not within the set or range of allowed values for a function or constructor. It is thrown when an argument is numerically valid but falls outside the specific constraints of the operation being performed. #RangeError is one of the standard, built-in error types that inherit from the generic Error object. #What is an #Operand in #JavaScript? In JavaScript, an #operand is a value or an expression that an #operator acts upon to produce a result. Operators are symbols or keywords (like +, =, or typeof) that perform operations on this data. #Key #Characteristics #of #Operands 1. #Values_being_manipulated: Operands are essentially the "nouns" of a JavaScript statement, while operators are the "verbs". 2. #Types: Operands can be of any JavaScript data type, including literal values (like numbers or strings), variables, or even the results of other, more complex, expressions. 3. #Position: In common binary operations (like addition), operands are positioned on either side of the operator (e.g., left operand and right operand). In unary operations (like negation), there is a single operand. The Curve Africa #JavaScript #MyTechJourney #TheCurveAfrica
To view or add a comment, sign in
-
So you want to write cleaner code in JavaScript - it's a game-changer. Functional composition is key. It's like building with Legos - you create these tiny functions that do one thing, and then you combine them to make something amazing. You define a function that takes multiple functions as arguments, and it returns a new function that applies the original functions in a specific order - it's pretty straightforward. It works. For example, you can create a `compose` function that takes multiple functions and returns a new function that applies them in a specific order - like this: ```javascript const compose = (...functions) => (x) => functions.reduceRight((acc, fn) => fn(acc), x); ``` And then you can use it to compose other functions, like `add2` and `multiply3`. It's simple: ```javascript const add2 = (num) => num + 2; const multiply3 = (num) => num * 3; const add2ThenMultiply3 = compose(multiply3, add2); console.log(add2ThenMultiply3(5)); // Output:``` But here's the thing - functional composition isn't just for synchronous functions. It also works with asynchronous functions, which is huge. You can create an `asyncCompose` function that takes multiple asynchronous functions and returns a new function that applies them in a specific order - like this: ```javascript const asyncCompose = (...fns) => (initialInput) => fns.reduceRight( (promise, fn) => promise.then(fn), Promise.resolve(initialInput) ); ``` And then you can use it to compose asynchronous functions, like `fetchData` and `transformData`. It's pretty cool: ```javascript const fetchData = (id) => new Promise((resolve) => { setTimeout(() => resolve(`Data for ${id}`), 1000); }); const transformData = (data) => `${data} transformed!`; const composedAsyncFunction = asyncCompose(transformData, fetchData); composedAsyncFunction(1).then(console.log); // Output after 1 second: "Data for 1 transformed!" ``` Now, to take it to the next level, you can use techniques like batching function calls and memoization. Memoization is like caching - it stores the results of expensive function calls so you don't have to repeat them. You can create a `memoize` function that takes a function and returns a new function that caches its results - like this: ```javascript const memoize = (fn) => { const cache = {}; return function (...args) { const key = JSON.stringify(args); if (!(key in cache)) { cache[key] = fn(...args); } return cache[key]; }; }; ``` It's a big deal. By using functional composition and these techniques, you can write more efficient and maintainable code in JavaScript - and that's what it's all about. Source: https://lnkd.in/g3-F4DKC #javascript #functionalprogramming #codingtips
To view or add a comment, sign in
-
🌟 10 Useful JavaScript Snippets You Might Not Know Quick, practical JS helpers that can save time and clean up your code! 💡 --- 1️⃣ Randomize an array (Fisher-Yates shuffle) ```javascript const shuffleArray = (arr) => arr.sort(() => Math.random() - 0.5); console.log(shuffleArray([1, 2, 3, 4, 5])); ``` 2️⃣ Flatten nested arrays ```javascript const flatten = (arr) => [].concat(...arr); console.log(flatten([1, [2, 3], [4, [5]]])); ``` 3️⃣ Check if an object is empty ```javascript const isEmpty = (obj) => Object.keys(obj).length === 0; console.log(isEmpty({})); // true ``` 4️⃣ Remove duplicates from an array ```javascript const unique = (arr) => [...new Set(arr)]; console.log(unique([1, 2, 2, 3, 3, 4])); ``` 5️⃣ Get current date in YYYY-MM-DD format ```javascript const today = () => new Date().toISOString().slice(0, 10); console.log(today()); ``` 6️⃣ Capitalize the first letter of a string ```javascript const capitalize = (str) => str.charAt(0).toUpperCase() + str.slice(1); console.log(capitalize("hello world")); ``` 7️⃣ Convert RGB to Hex ```javascript const rgbToHex = (r, g, b) => "#" + ((1 << 24) + (r << 16) + (g << 8) + b).toString(16).slice(1); console.log(rgbToHex(255, 100, 50)); ``` 8️⃣ Wait/delay function ```javascript const delay = (ms) => new Promise(resolve => setTimeout(resolve, ms)); await delay(2000); // waits 2 seconds ``` 9️⃣ Copy text to clipboard ```javascript const copyToClipboard = (text) => navigator.clipboard.writeText(text); copyToClipboard("Hello, devs! 👨💻"); ``` 🔟 Extract parameters from URL ```javascript const getParams = (url) => Object.fromEntries(new URL(url).searchParams); console.log(getParams('https://lnkd.in/g3Y-T5jw')); ``` --- 📌 Which snippet did you find most useful? Have a better version? Share below! 👇 --- 📌 Follow Sasikumar S for more hands-on developer content ❤️ Join skAI – Daily Developer Learning Community for daily tips, growth hacks & career opportunities 💌 Repost to help others in your network 🤝 Connect: sasiias2024@gmail.com 💟 Explore more: sk-techland.web.app #JavaScript #WebDevelopment #CodingTips #JS #DeveloperTools #Programming #CodeSnippets #TechTips #Frontend #LearnToCode
To view or add a comment, sign in
-
🎯 Understanding how JavaScript actually works under the hood I've been working with JavaScript for some time, but recently had a breakthrough moment understanding the JavaScript runtime environment and it's changed how I think about my code. Here's what I learned: 💡 JavaScript is single-threaded, but not limited The runtime uses a clever coordination system: Call Stack, Web APIs, Task Queue, and Microtask Queue working together. This is why JavaScript can handle multiple operations simultaneously without blocking. 💡 The Event Loop is the orchestrator, It continuously monitors the call stack and queues, deciding what executes next. When the call stack is empty, it picks tasks from the queues - prioritizing microtasks (promises) over regular tasks (setTimeout callbacks). 💡 Web APIs are the secret weapon, Operations like fetch(), setTimeout(), and DOM events don't run in JavaScript itself - they're handled by browser APIs. This keeps the main thread free and responsive. 💡 Execution order becomes predictable; Understanding the flow helps: Synchronous code executes first → then Microtasks (promises) → then Tasks (callbacks). This knowledge is valuable for debugging unexpected behaviors and race conditions. Let me demonstrate with a simple JavaScript example: console.log("Start"); setTimeout(() => { console.log("Timeout callback"); }, 1000); Promise.resolve().then(() => { console.log("Promise callback"); }); console.log("End"); Output: "Start" → "End" → "Promise callback" → "Timeout callback" Why this order? 1. "Start" and "End" execute first because they're synchronous code on the Call Stack 2. setTimeout is sent to Web APIs to handle the timer, then its callback goes to the Task Queue 3. Promise callback goes directly to the Microtask Queue 4. When the Call Stack is empty, the Event Loop checks the Microtask Queue FIRST (priority!) 5. Promise callback executes before setTimeout callback, even though setTimeout was written first 6. Finally, setTimeout callback executes from the Task Queue This demonstrates the key principle: Microtasks always execute before Tasks, regardless of when they were registered. 📊 Swipe to see the animated visualization showing exactly how this code flows through the JavaScript runtime environment Key insight: JavaScript's runtime architecture enables powerful patterns for handling asynchronous operations. Understanding how the call stack, event loop, and queues interact provides a solid foundation for writing efficient, predictable code and troubleshooting complex scenarios. This is my first technical deep-dive post, and I'm excited to share more learnings as I continue exploring JavaScript fundamentals. #JavaScript #WebDevelopment #RuntimeEnvironment #SoftwareEngineering #TechLearning
To view or add a comment, sign in
-
💛 JavaScript Functions (Part 2) — Types of Functions Explained Clearly 🔥 In JavaScript, functions are not all the same. How you define a function changes: ▪️hoisting behavior ▪️readability ▪️this binding ▪️how it’s used in real projects Let’s explore the most important types 👇 ♦️ Function Statement (Function Declaration) function greet() { console.log("Hello!"); } ✅ Key Points ▪️Fully hoisted ▪️Can be called before definition ▪️Stored completely during memory creation phase greet(); // works 💡 Best for general-purpose logic ♦️ Function Expression A function assigned to a variable. var add = function (a, b) { return a + b; }; ⚠️ Important ▪️Variable is hoisted as undefined ▪️Function is not hoisted add(); // ❌ TypeError 💡 Useful when functions behave like values ♦️ Anonymous Function A function without a name. setTimeout(function () { console.log("Hello"); }, 1000); 🧠 Key Idea ▪️Used where a function is needed temporarily ▪️Cannot exist on its own ▪️Mostly used as callbacks ♦️ Named Function Expression (NFE) A function expression with a name. const factorial = function fact(n) { if (n === 0) return 1; return n * fact(n - 1); }; ✅ Benefits ▪️Name is available inside the function only ▪️Helpful for recursion ▪️Better debugging (stack traces) fact(5); // ❌ not accessible outside ♦️ Arrow Functions 🏹 Introduced in ES6 for cleaner syntax. const multiply = (a, b) => a * b; 🔹 Differences from Normal Functions ▪️No own this ▪️No arguments object ▪️Lexically binds this Cannot be used as constructors const obj = { x: 10, show: () => console.log(this.x) }; obj.show(); // undefined ♦️ First-Class Functions 🥇 JavaScript treats functions as values. This means functions can: ✔️ Be assigned to variables ✔️ Be passed as arguments ✔️ Be returned from other functions 🔹 Example function greet() { return function () { console.log("Hello!"); }; } const sayHello = greet(); sayHello(); 👉 This is the foundation of: Callbacks, Closures and Higher-Order Functions 💡 Why This Matters Understanding function types helps you: ✅ Avoid hoisting bugs ✅ Use correct syntax in interviews ✅ Write cleaner, modern JS ✅ Understand React & async patterns 📌 This was Part 2 Next up 🔥 👉 Part 3: Higher-Order Functions, Callback Functions, IFFE & Real-World Use Cases If this helped you, drop a 💛 or share 🔁 #JavaScript #JSInternals #LearnJavaScript #WebDevelopment #ProgrammingConcepts #WebDevJourney #BuildInPublic
To view or add a comment, sign in
-
-
So, you think you know JavaScript objects inside and out. But, let's get real - do you really understand how they inherit properties? It's like trying to find a specific book in a huge library, you gotta know where to look. JavaScript's secret sauce is prototypes. Every object has this internal prototype link that's like a map to its ancestors. When you try to access a property, JavaScript goes on a search mission through the prototype chain - it's like following a trail of breadcrumbs. Here's the lowdown: you try to access a property on an object, and if it's there, you get its value, no big deal. But, if it's not, JavaScript checks the object's prototype, and if it's not there, it keeps searching until it finds the property or hits a dead end. It's kinda like when you're trying to remember where you put your keys - you check the usual spots, and if you still can't find them, you start searching everywhere else. Simple. Now, let's dive deeper - the prototype chain is like a family tree, where each object inherits properties from its parent. And, just like in real life, the properties you inherit from your parents are shared with your siblings, but the ones you own are unique to you. For example, take a look at this code: ```javascript const animal = { eats: true, walk: function() { console.log('Animal walks'); } }; const rabbit = { jumps: true }; Object.setPrototypeOf(rabbit, animal); console.log(rabbit.jumps); // true console.log(rabbit.eats); // true rabbit.walk(); // "Animal walks" ``` In this example, the `rabbit` object inherits properties from the `animal` object - it's like the `rabbit` is saying, "Hey, I've got a parent who can teach me some cool stuff." And, here's the thing - methods on the prototype are shared across all instances, like a family recipe that's passed down through generations. But, properties on the instance are unique to each object, like a personal journal that's just for you. Oh, and one more thing - `__proto__` points to the object's prototype, like a sign that says, "Hey, my parent is over here." And, `prototype` is on constructor functions, like a blueprint for building a house. Now, you might be wondering about ES6 classes - they're like a fancy new car that's actually just a redesigned old model. They're syntactic sugar over constructor functions and prototypes, making it easier to create objects that inherit properties. And, if you're into React, you should know that class components use prototypes, but functional components don't - it's like the difference between a big, fancy restaurant and a food truck. Source: https://lnkd.in/ghnuf2BC #JavaScript #Prototypes #Inheritance #Coding
To view or add a comment, sign in
More from this author
Explore related topics
Explore content categories
- Career
- Productivity
- Finance
- Soft Skills & Emotional Intelligence
- Project Management
- Education
- Technology
- Leadership
- Ecommerce
- User Experience
- Recruitment & HR
- Customer Experience
- Real Estate
- Marketing
- Sales
- Retail & Merchandising
- Science
- Supply Chain Management
- Future Of Work
- Consulting
- Writing
- Economics
- Artificial Intelligence
- Employee Experience
- Workplace Trends
- Fundraising
- Networking
- Corporate Social Responsibility
- Negotiation
- Communication
- Engineering
- Hospitality & Tourism
- Business Strategy
- Change Management
- Organizational Culture
- Design
- Innovation
- Event Planning
- Training & Development