Javascript Coding Interview Questions- You Must Know Them

Поділитися
Вставка
  • Опубліковано 26 гру 2024

КОМЕНТАРІ • 69

  • @MonsterlessonsAcademy
    @MonsterlessonsAcademy  3 місяці тому

    WATCH NEXT: Javascript Interview Questions and Answers - Dominate Your Next Interview - ua-cam.com/video/wnYKH2dO620/v-deo.htmlsi=5DfbGEfhXWiiv0a_

  • @Vivek-Nishad
    @Vivek-Nishad Рік тому +9

    Object.assign and spread operator only work it you have a flat object like {a:1, b:2} But if you have nested object like {a:1,b:2,c:{d:3}} it will copy value of a and b but reference of c,d.
    so, if you want to copy nested objects you can use "structuredClone(obj)" or "JSON.parse(JSON.stringify(obj))"

    • @MonsterlessonsAcademy
      @MonsterlessonsAcademy  Рік тому +2

      You are totally right

    • @vishalupadhayay6391
      @vishalupadhayay6391 Рік тому +1

      JSON.parse(JSON.stringify(obj)) will not work if the object has Arrays, Functions, and Date nested within. In such a scenario, we may have to use loadash or write one custom function to handle Arrays, Functions, and Date objects.

    • @KAZVorpal
      @KAZVorpal 4 місяці тому +2

      I was here to specifically raise the same objection.
      But if I were an interviewer, I might be wanting an answer that showed understanding of the LOGIC of cloning.
      In other words, a recursive function that checks if the passed value is an object, returns it if not, but if it is, loops through its properties and calls ITSELF on each property that is an object, gradually building a new object, then returns the final product.
      I would not be satisfied with someone just using structuredClone() because I'd want to see their coding/algorithmic knowledge.

  • @n_fan329
    @n_fan329 Рік тому +1

    for the last question..we can also do Object.entries(mapping).sort((a,b)=>a

  • @AndreaDragotta
    @AndreaDragotta Рік тому +4

    Regarding the clone example, be aware that these are shallow copies (they do not work correctly when the object contains other objects). If you need a deep copy you should use the new "structuredClone" api or the usual trick with "JSON.parse(JSON.stringify(obj))"

    • @MonsterlessonsAcademy
      @MonsterlessonsAcademy  Рік тому +1

      I have a full video about shallow comparison vs deep comparison.
      ua-cam.com/video/re0G89DwOb8/v-deo.htmlsi=snVLRIAqpU0_5OuN

  • @SuperMatsumoto23
    @SuperMatsumoto23 Рік тому +8

    I am sooo grateful for this video!! I am a junior developer currently preparing for my tech interviews, and some of this stuff was difficult to understand while just reading a text explanation. Thank you for showing these examples step by step, these have helped me get a better understanding of the theory. ♥

    • @MonsterlessonsAcademy
      @MonsterlessonsAcademy  Рік тому

      Glato to hear that. For interview preparation you might be interested in my Javascript interview questions course where you learn 56 different topics which fully cover Javascript.
      monsterlessons-academy.com/courses/javascript-interview-questions-coding-interview/

    • @francescaperfume
      @francescaperfume 5 місяців тому

      😊​@@MonsterlessonsAcademy

    • @francescaperfume
      @francescaperfume 5 місяців тому

      ​@@MonsterlessonsAcademy😊

    • @francescaperfume
      @francescaperfume 5 місяців тому

      ​@@MonsterlessonsAcademy😊

    • @francescaperfume
      @francescaperfume 5 місяців тому

      ​@@MonsterlessonsAcademy😊

  • @joeldaros
    @joeldaros 2 роки тому +2

    I really like your videos, you get straight to the point. Please make more videos like this one!

    • @MonsterlessonsAcademy
      @MonsterlessonsAcademy  2 роки тому +1

      I have now a full course of 59 coding exercises for Javascript interview.
      monsterlessons-academy.com/courses/javascript-interview-questions-coding-interview

  • @bendevweb89
    @bendevweb89 2 роки тому +1

    As a Junior Developer your content helps me a lot to prepare for interviews and improve my logic
    Thank you very much 👍

  • @mohammadyousuf1567
    @mohammadyousuf1567 2 роки тому

    I am addicted to your style of teaching .. : )

  • @jonathanjohnson2785
    @jonathanjohnson2785 Рік тому +1

    I don't have words to fully express my gratitude. Closures, cloning are things I found hard to understand but your style of teaching made everything so simple to understand. Thank you so much and all the best❤👍👍👏

  • @orz5516
    @orz5516 Рік тому

    In the findVowels i would expect a senior developer would do it with an object because with includes that complexity is much higher.
    With an object you can just iterate the string once and check each time if the char is a vowel with O(1) complexity

    • @MonsterlessonsAcademy
      @MonsterlessonsAcademy  Рік тому +4

      There are different ways. Object is also not ideal. Regexr is easier that
      const vowelCount = str => {
      const regex = /[aeiouAEIOU]/g
      const s = str.match(regex)
      return s ? s.length : 0
      }

    • @orz5516
      @orz5516 Рік тому

      @@MonsterlessonsAcademy
      And thanks for the videos, you are great!

  • @clement2814
    @clement2814 2 роки тому

    Thank you, clear and concise

  • @damienspectre4231
    @damienspectre4231 Рік тому +1

    For the first problem - I understand closures and you are returning a fucntion within the parent function that returns the secret. but Im curious - why not return the secret string directly instead of within the child function? its a const and its private to the someFn() and cant be modified once declared...

    • @MonsterlessonsAcademy
      @MonsterlessonsAcademy  Рік тому +1

      It was just an example to show closures. environment variables should not be written in code in any case.

  • @dragosp.7635
    @dragosp.7635 2 роки тому

    at 3:50. I see it also work const clone=object. Is it a good practice?

    • @MonsterlessonsAcademy
      @MonsterlessonsAcademy  2 роки тому +1

      It is not. You assign the reference to the object and not a new object with a value. Try to change property of clone and check the value of both objects.

  • @leojohn6702
    @leojohn6702 Рік тому

    Quick question. Currently building my portfolio projects. But I have no knowledge of data structures and algorithms. Should i start training after my portfolio will be completed? Or prior the portfolio?

    • @MonsterlessonsAcademy
      @MonsterlessonsAcademy  Рік тому +2

      Do a portfolio, CV and then improve your knowledge and add it. If you are a junior forget about data structures and algorithms at all. learn language and framework.

  • @dmytro-skh
    @dmytro-skh Рік тому +3

    as for me reduce in the last example is too complicated to understand and debug. Nice for an interview but I would avoid such things in real code. I.e. if jun dev will have to work with that piece of code. In general good video, will look others on the channel too :)

    • @keneldridge
      @keneldridge Рік тому

      I like Object.keys(counterObject).sort((a,b) => { return a > b ? -1 : 0 })[0]

  • @Shivam-sl4sp
    @Shivam-sl4sp Рік тому

    Thank you man !!

  • @yeti9537
    @yeti9537 3 роки тому

    This is great. Thanks!

  • @AndrewTSq
    @AndrewTSq 2 роки тому +1

    The count vowels i just did [...str.toLowerCase().matchAll(/[aeiou]/g)].length not sure it was right, but worked on my examples :) fun questions :)

  • @cryptopinky2355
    @cryptopinky2355 Рік тому

    Why do we write acc[1] and el[1]? what is the index for and why is it always 1?

    • @MonsterlessonsAcademy
      @MonsterlessonsAcademy  Рік тому

      Because there are just 2 elements in the array and we want to work with the second one.

  • @OliaYarukhina
    @OliaYarukhina Рік тому

    Круто! Дякую! Цікаво звідки Ви, Олександре?)

  • @testify7228
    @testify7228 2 роки тому

    Hi,
    For last question
    To get element which have max occurrence:
    After creating object, can we use .sort() nd do descending order based on Occurance nd then return first value from sorted object.
    Is it correct?

    • @MonsterlessonsAcademy
      @MonsterlessonsAcademy  2 роки тому

      Hi, There are different ways to solve the same task.

    • @testify7228
      @testify7228 2 роки тому

      @@MonsterlessonsAcademy ok dude. Thanks for replay
      I saw ur 59 interview questions video course, really worth fir spending time in it

  • @amitkrishna2412
    @amitkrishna2412 2 роки тому

    Hi , Is there a document or a list of such interview questions that you have maintained?which I can follow?

    • @MonsterlessonsAcademy
      @MonsterlessonsAcademy  2 роки тому +1

      No I don't have something like this. But I have a full course with 57 Javascript questions which covers all knowledge that you need.
      monsterlessons-academy.com/courses/javascript-interview-questions-coding-interview

  • @doniaelfouly4142
    @doniaelfouly4142 Рік тому

    thank you so much

  • @sameoldsteven9571
    @sameoldsteven9571 Рік тому

    cant we solve the last question using Set?

  • @jjjj5452
    @jjjj5452 Рік тому

    Now just need to get an interview that asks one of these 5 questions...

  • @sliceem88
    @sliceem88 3 роки тому

    Best !

  • @thisisryker
    @thisisryker 3 місяці тому

    why using .reduce() is better ? You telling to use .reduce() is better, but never explain why.

    • @MonsterlessonsAcademy
      @MonsterlessonsAcademy  3 місяці тому

      reduce is a functional and declarative way of writing code in comparison to for loops. It returns the direct result, avoids creating additional variables before and doesn't have side effects.

  • @_Greenflag_
    @_Greenflag_ Місяць тому

    Not good. Be careful when labeling other versions as "beginner" if your own code is not good, performant, or clean (and be careful when you label a version as "more advanced" when it's only a question of syntax). There is absolutely nothing wrong with the code commented at 8:20 (except for using "let char" instead of "const char"). Your version is less performant than the "beginner" version; the reduce function has higher space and time complexity. 9:20 no, this is not good at all. Space and time complexity are f. up. Correction, just iterate once over all array :
    function reverseString(str: string) {
    let result = '';
    for (let i = str.length - 1; i >= 0; i--) {
    result += str[i];
    }
    return result;
    }
    const reversed = reverseString('hello');
    Last exercice, the worst of your serie. Time / space complexity f. up, and way too much code. Correction:
    function mostCommonString(strings: string[]): string {
    const hashMap: { [element: string]: number } = {};
    let maxElement = strings[0];
    let maxValue = 0;
    for (const element of strings) {
    hashMap[element] = (hashMap[element] || 0) + 1;
    if (hashMap[element] > maxValue) {
    maxValue = hashMap[element];
    maxElement = element;
    }
    }
    return maxElement;
    }

    • @MonsterlessonsAcademy
      @MonsterlessonsAcademy  Місяць тому

      Performance doesn't mean everything. 90% of the time readability is more important to make your code maintainable. If your code runs on 100 records it doesn't matter what's inside. Premature optimisations are not needed. Fix performance when it becomes a problem.

  • @KAZVorpal
    @KAZVorpal 4 місяці тому +1

    NOOO!
    Do not count all the strings, then SEPARATELY find the largest with a second reduce. How wasteful.
    Mark the highest all along, saving you an extra loop.
    Like this:
    const max = {name: "", count:0}
    target.reduce((namelist, name) => {
    if(namelist.has(name)) {
    const current = namelist.get(name)+1;
    namelist.set(name, current);
    (current > max.count) && ([max.name, max.count] = [name, current]);
    } else
    namelist.set(name, 1);
    return namelist;
    }, new Map);
    return max;

    • @MonsterlessonsAcademy
      @MonsterlessonsAcademy  4 місяці тому

      It depends on the size of the array. 2 functions are less performant but more readable. But if we work with 10 element then who cares.

    • @KAZVorpal
      @KAZVorpal 4 місяці тому

      @@MonsterlessonsAcademy If done clearly, it's actually more readable as a single function.
      More importantly, it's better to impress the interviewer with how well you code as a JOB...and the better performance of doing it as a single loop would be far better in many situations where you're working with a large amount of data.
      Your code should be elegant and efficient, not just the most basic expression.