Это видео недоступно.
Сожалеем об этом.

JavaScript Interview Prep - How Would You Improve This Code?

Поделиться
HTML-код
  • Опубликовано: 16 июл 2023
  • In this video, we'll be having a look at a JavaScript function that has very typical functionality and seeing how we can make it better.
    🏫 My Udemy Courses - www.udemy.com/...
    🎨 Download my VS Code theme - marketplace.vi...
    💜 Join my Discord Server - / discord
    🐦 Find me on Twitter - / dcodeyt
    💸 Support me on Patreon - / dcode
    📰 Follow me on DEV Community - dev.to/dcodeyt
    📹 Join this channel to get access to perks - / @dcode-software
    If this video helped you out and you'd like to see more, make sure to leave a like and subscribe to dcode!
    #dcode #javascript #softwareengineer

Комментарии • 9

  • @AlexCernat
    @AlexCernat Год назад +11

    more to improve:
    1. use async/await
    2. create an array of li elements and then use .replaceChildren(...liArray) (insert html is dangerous)
    3. do not use template strings as the user variable could be "garbled" (xss)
    4. error handling (especially on fetch)

  • @jaybarls
    @jaybarls Год назад

    This is really good, thankyou - would love to see more like this, as it's helpful to see real examples of how to improve code, beyond it just working. Building tests for one of my apps has really taught me how useful it is to break up code into separate, single-use functions where possible - even going back to your own codebase, making something easier to read is huge for being able to understand, maintain and update it.

  • @Not_TVs_Frank
    @Not_TVs_Frank 4 месяца назад

    Assuming the score is a numeric value could lead to unexpected score values. Passing the score through Number() can help. although non-numeric strings like "oops!" will convert to NaN. You could also test the output is an integer (Number.isInteger()) so that converting an errant string into NaN doesn't turn your score into NaN.

  • @bmehder
    @bmehder Год назад

    Yes, please make more videos like this. It would be cool if you included the original code in a manner that could be executed. So, in this example, we would need to have some data to fetch. Then we could run our code after refactoring to make sure we didn't break anything.

    • @dcode-software
      @dcode-software  Год назад

      Good idea! I'll look at doing something like this next time

  • @abdelazizchakir1694
    @abdelazizchakir1694 Год назад

    I want to learn programming how can I do it

  • @chrismiller3650
    @chrismiller3650 Год назад

    Imagine going to an interview and instead of being tested on arbitrary things that you actually get tested for the job at hand.

  • @maureenbucchin7405
    @maureenbucchin7405 Год назад

    'Promo sm'

  • @md2perpe
    @md2perpe Год назад +4

    Insert all HTML at once instead of one piece at a time:
    userList.innerHTML = users.map(({ name, score }) => `${name} (${score})`).join("");