💻 JavaScript Interview Question You will be given a string and two indexes (a and b). Your task is to reverse the portion of that string between those two indices inclusive. str = "javascript", a = 1, b = 5 --> "jcsavaript" East right ? But rather than traversing the string and using 2-pointer technique, you have to use the inbuilt functions of javascript. This tests your understanding of the language and how it works internally. function solve(st, a, b){ return st.slice(0,a)+(st.slice(a, b+1).split("").reverse().join(""))+st.slice(b+1); } Feel free to discuss more in comments 🖐 #javaScript #CodingInterview #WebDevelopment #Frontend #React
Reverse String Portion with JavaScript
More Relevant Posts
-
15 JavaScript interview questions. Functions, Scope & Closures. Answer karo comments mein 👇 Functions Q1. What is the difference between function declaration and function expression? Q2. What is an arrow function? How is it different from a regular function? Q3. What is the difference between parameters and arguments? Q4. What are default parameters in JavaScript? Q5. What is a pure function? Q6. What is a higher-order function? Scope Q7. What are the different types of scope in JavaScript? Q8. What is the scope chain in JavaScript? Q9. What is lexical scope? Closures Q10. What is a closure in JavaScript? Q11. What are practical use cases of closures? Q12. What is the classic closure bug in loops — and how do you fix it? Q13. How does React use closures internally? Q14. What is the difference between closure and scope? Q15. What is an IIFE and why is it used? Full answers + code on GitHub 👇 https://lnkd.in/dj72-XEi #JavaScript #JStoReact #InterviewPrep #WebDevelopment #Frontend #30DayChallenge
To view or add a comment, sign in
-
JavaScript Interview Question (Confusing but Important 🤯) What will be the output? console.log([] == []); console.log([] === []); console.log({} == {}); console.log({} === {}); 👉 Answer: All will be false Why? Arrays and objects in JavaScript are stored in memory by reference, not by value. Each [] or {} creates a new object with a different memory address, and JavaScript compares references — not structure or content. Same shape ≠ same reference 📌 This is one of the most common JavaScript interview traps. #JavaScript #InterviewQuestions #WebDevelopment #Frontend #Backend #CodingTips
To view or add a comment, sign in
-
🚨 JavaScript Interview Question What will be the output? const obj = { name: "Frontend", regularFunc: function () { console.log(this.name); }, arrowFunc: () => { console.log(this.name); } }; obj.regularFunc(); obj.arrowFunc(); Both functions are inside the same object. But the output is different. This question tests understanding of: • this binding • Arrow functions vs regular functions • Execution context in JavaScript Many developers assume both will print the same value. What do you think the output will be? #JavaScript #FrontendInterview #ReactJS #FrontendDeveloper #JavaScriptConcepts #ProductBasedCompany
To view or add a comment, sign in
-
🚀 **JavaScript Interview Question** What will be the output of this code? ```js const obj = { a: { b: 0 } }; const v1 = obj?.a?.b || 42; const v2 = obj?.a?.b ?? 42; console.log(v1, v2); ``` 🤔 **Think before you scroll...** --- #JavaScript #Frontend #WebDevelopment #CodingInterview #ReactJS
To view or add a comment, sign in
-
🚨 JavaScript Interview Question What will be the output? const obj = { name: "Frontend", greet: function () { console.log(this.name); } }; const greet = obj.greet; greet(); greet.call(obj); greet.bind(obj)(); This question tests understanding of: • this binding • call() • bind() • Function invocation context Many developers expect all three calls to behave the same. But JavaScript handles this differently depending on how the function is invoked. What do you think the output will be? #JavaScript #FrontendInterview #ReactJS #FrontendDeveloper #JavaScriptConcepts #ProductBasedCompany
To view or add a comment, sign in
-
🚨JavaScript Interview Question What will be the output? function greet(name) { if (name === undefined) { console.log("Hello, guest!"); } else { console.log("Hello, "+ name); } greet(); greet("Anas"); greet("Anas", "How are you?"); Looks simple... but there's a twist What will be the output? Why does the last call behave differently? Bonus: How does JavaScript handle extra arguments? #JavaScript #FrontendInterview #WebDevelopment #CodingInterview #ProductBasedCompany
To view or add a comment, sign in
-
🚨 JavaScript Async Interview Question What will be the output? async function test() { console.log("1"); setTimeout(() => { console.log("2"); }, 0); await Promise.resolve(); console.log("3"); } console.log("4"); test(); console.log("5"); This question tests understanding of: • Call Stack • Async/Await behavior • Microtask queue (Promises) • Macrotask queue (setTimeout) • JavaScript Event Loop Many developers get the order wrong the first time. What do you think the output will be? #JavaScript #FrontendInterview #AsyncJavaScript #EventLoop #ReactJS #FrontendDeveloper #ProductBasedCompany
To view or add a comment, sign in
-
One of the most common JavaScript interview questions: "Why does setTimeout with 0ms delay not run immediately?" Most developers cannot answer this correctly. Here is the full explanation: JavaScript is single-threaded. It can only do one thing at a time. The Event Loop is how it manages everything else. The execution order is always the same: 1 — Synchronous code runs first All regular code on the Call Stack executes immediately. 2 — Microtasks run second Promises, async/await — these run before anything else once the Call Stack is empty. 3 — Macrotasks run last setTimeout, setInterval, DOM events — these wait until ALL microtasks are done. This is why setTimeout with 0ms still runs after a Promise. The Promise is a microtask. setTimeout is a macrotask. Microtasks always win. Understanding this prevents real bugs in production — async state updates, race conditions, unexpected render order. Save this post for your next async debugging session. Have you ever been confused by JavaScript async order? Drop a comment below. #JavaScript #WebDevelopment #Frontend #SoftwareEngineering #AsyncJavaScript
To view or add a comment, sign in
-
-
15 JavaScript interview questions. Promises & Async/Await. Answer karo comments mein 👇 Promises Q1. What is a Promise in JavaScript and why does it exist? Q2. What is the difference between resolve and reject? Q3. What does .then() return? Q4. What is the difference between .catch() and the second argument of .then()? Q5. What does .finally() do? Async/Await Q6. What is async/await and how does it relate to Promises? Q7. What does an async function always return? Q8. Can you use await outside an async function? Q9. What happens if you don't use try/catch with async/await? Q10. What is the difference between sequential and parallel async calls? Promise Methods Q11. What is the difference between Promise.all and Promise.allSettled? Q12. What is Promise.race and when would you use it? React Connection Q13. Why can't useEffect callback be directly async? Q14. What is the standard loading/error/data pattern in React? Q15. What is the difference between async errors and sync errors in React? Full answers + code on GitHub 👇 https://lnkd.in/dj72-XEi #JavaScript #JStoReact #InterviewPrep #WebDevelopment #Frontend #ReactJS #30DayChallenge #JavaScriptTips #FrontendDeveloper #100DaysOfCode
To view or add a comment, sign in
-
🚨 JavaScript Interview Question (Advanced 🔥) What will be the output? 🤔 function Person(name) { this.name = name; } Person.prototype.getName = function () { return this.name; }; const p1 = new Person("Suman"); const p2 = { name: "Rahul", }; console.log(p1.getName()); console.log(p1.getName.call(p2)); Looks simple… but there’s a twist 👀 👉 What will be the output? 👉 Why does the second call behave differently? Bonus: What concept is being tested here? 🔥 #JavaScript #FrontendInterview #Prototypes #ThisKeyword #WebDevelopment
To view or add a comment, sign in
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