Dos and Donts: Best Practices When Learning JavaScript

แชร์
ฝัง
  • เผยแพร่เมื่อ 6 ก.พ. 2025

ความคิดเห็น • 51

  • @Tubeatorium2
    @Tubeatorium2 10 ปีที่แล้ว +14

    The narrator is sooo professional and then, at 8:23, with a barely detectable break in her demeanor: "... something called Automatic Semi-Colon Insertion. It sounds complicated and perhaps a little painful..." I love that she did that :) Very funny

  • @meruzhansargsyan1476
    @meruzhansargsyan1476 4 ปีที่แล้ว +1

    Here is a tip for people watching in 2020 or later: never use var, use const and let to declare variables. Also put the statement “use strict”; at the top of your code. This makes sure that your code is as modern as possible

    • @AndrewTSq
      @AndrewTSq 2 ปีที่แล้ว

      I am not sure what they do in the first example, Looks like they just return an array with same length but filled with zeros. This i would write like function clr(o) { let newArray = new Array(o.length); newArray.fill(0); return newArray; }, or use let newArray = Object.keys(o) but I am not really sure what they do to be honest :D

  • @victornaut
    @victornaut 8 ปีที่แล้ว +6

    Some of these are applicable not only to JS, but to any programming language.

  • @StewartLynch
    @StewartLynch 10 ปีที่แล้ว +5

    I think that there is an error in that first example of choosing good variable names.
    This will cast all values of the object as 0
    Should the line theArray[i] = 0 not be
    theArray[i] = obj[key];

    • @oreilly
      @oreilly  10 ปีที่แล้ว

      We can look into that. Thanks for letting us know.

    • @ChrisTian-ox5nr
      @ChrisTian-ox5nr 9 ปีที่แล้ว

      +Stewart Lynch That is exactly what I thought when I saw that as well.

    • @hamyncheese
      @hamyncheese 8 ปีที่แล้ว +4

      +Stewart Lynch +O'Reilly If you read the overly descriptive names in the middle part of that example, the function is named "createZeroArrayTheSameSizeAsObject"
      So, to answer your question 2 years later, No, the line should not be what you think it should be, it is correct the way it is written.

    • @TheChipBandit
      @TheChipBandit 7 ปีที่แล้ว

      You do have a point, the code does what is supposed to do(based on the first two examples), however the final version name implies that the function will convert obj to an array, however it does not do that.

  • @jessupboyus
    @jessupboyus 9 ปีที่แล้ว +17

    write code for humans not computers. Don't Repeat Yourself. Keep it Simple.

    • @victornaut
      @victornaut 8 ปีที่แล้ว +1

      Dry kiss.
      Don't repeat your self + Keep it simple stupid.

    • @lukedupont6238
      @lukedupont6238 8 ปีที่แล้ว +3

      No - please, please, please write code for computers. Humans are ambiguous and assumptive and vague and tend to give very, very bad instructions / descriptions that can be misinterpreted in all kinds of ways. Computers keep us honest and force us to adopt higher standards of logic, reason, and consistency. (Ok, well, maybe not so much if you're coding in JavaScript, but, I digress...)

    • @339blaster
      @339blaster 8 ปีที่แล้ว

      Old Account Lol

    • @dayvie9517
      @dayvie9517 6 ปีที่แล้ว

      @@lukedupont6238 Okay, so everyone has to program in assembly language now, because else its too ambiguous lul

  • @IsaacAsante17
    @IsaacAsante17 7 ปีที่แล้ว

    Impressed by this insightful video. I'm subscribing now!

  • @NoahNobody
    @NoahNobody 10 ปีที่แล้ว +2

    Some really nice tips. Thanks for the teaser.

  • @ArhisAlight
    @ArhisAlight 8 ปีที่แล้ว

    Thank you for these tips!

  • @tolich3
    @tolich3 8 ปีที่แล้ว

    Shouldn't message be set to div.innerHTML instead of empty string? What if we supposed to process more than one array?

  • @bustnoutloadedcaliber8717
    @bustnoutloadedcaliber8717 9 ปีที่แล้ว

    great video o'reilly , its better then other videos i saw :)

  • @ehssilva
    @ehssilva 10 ปีที่แล้ว

    Thanks

  • @odunladeoluwaseun7880
    @odunladeoluwaseun7880 8 ปีที่แล้ว

    I went through everything on JavaScript at 3wschools, I can use all of them individually but still can't build any meaningful app. I can change contents on DOM, change styles, change image SRC but that is where it ends. where can I learn advance stuffs, like building a real life app

    • @dizhar8888
      @dizhar8888 8 ปีที่แล้ว +3

      odunlade oluwaseun JavaScript is not a full language. It's mostly used for manipulating the HTML or XML tags. you might want to look into PHP, node.js, Ruby on rails or Python (Django).

    • @odunladeoluwaseun7880
      @odunladeoluwaseun7880 7 ปีที่แล้ว

      RsLeonardo1 thank you

  • @english-cantonese
    @english-cantonese 8 ปีที่แล้ว

    thank you!

  • @chubbyBunny94
    @chubbyBunny94 7 ปีที่แล้ว

    What consoles should I download to practise on my PC?

    • @tslqs
      @tslqs 7 ปีที่แล้ว

      athere are alot of options, here are a few: atom, sublime, brakets, visual studio code,

  • @ChrisTian-ox5nr
    @ChrisTian-ox5nr 9 ปีที่แล้ว +4

    Very good stuff women.

    • @goldilockszone4389
      @goldilockszone4389 8 ปีที่แล้ว +2

      She probably is a scribe - who is just reading out from a script - female voice are nicer to listen to

  • @practicerepeat5927
    @practicerepeat5927 9 ปีที่แล้ว

    I tried this and does not work inside my body:
    function arrayFromObject (obj) {
    var theArray = [];
    var i = 0;
    for (var key in obj) {
    theArray[i] = 0;
    i++;
    }
    return theArray;
    }

    • @QwertyNPC
      @QwertyNPC 9 ปีที่แล้ว

      +Practice Repeat
      Have You made an object with some properties and passed it in to arrayFromObject ?

    • @jessupboyus
      @jessupboyus 9 ปีที่แล้ว

      yeah man you have to make an object then call the function (obj)

  • @0x28
    @0x28 9 ปีที่แล้ว

    This is excellent marketing, might I say!

  • @ReinardDolleschel
    @ReinardDolleschel 10 ปีที่แล้ว +2

    Useful intro and appreciate the clear voice, but drop the silly stock pictures. "You can't have two variable names with the same names." might want to word that better.

    • @mrapatheist
      @mrapatheist 10 ปีที่แล้ว +1

      I thought the pictures were the best part!

    • @0x28
      @0x28 9 ปีที่แล้ว

      Reinard Dolleschel You're just another reason why programmers are robotic idiots. Have some feelings, would you? Fucking robot.

    • @ReinardDolleschel
      @ReinardDolleschel 9 ปีที่แล้ว

      0x28 Wow there. Easy. No need to be so aggressive. Emotional human!

    • @0x28
      @0x28 9 ปีที่แล้ว

      Reinard Dolleschel I'm showing my emotions, baby. You know what I'm sayin' dawg.

  • @dayvie9517
    @dayvie9517 6 ปีที่แล้ว +5

    Best practices for JavaScript: use let and const instead of var if you can.

    • @ThePacman196
      @ThePacman196 6 ปีที่แล้ว

      as a basic javascript boi, why is this a good practice? i have seen const before but not let

    • @gregsoares6021
      @gregsoares6021 6 ปีที่แล้ว

      ​@@ThePacman196 Looking into the Documentation here's what I found to be the main differences between var VS let & const:
      let & const - are block level variables and only initialized when that block is executed. ( developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/let )
      Differently from var, which inherits its scope to the function in which it resides, or is implicitly a global if declared outside a function.
      Though the main difference here is because or a term called "hoisting", which 'hoists' all declarations of var variables to the top of their perspective scope.
      (developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/var#var_hoisting)
      Conclusion: If you declare any var inside some if statement that might run once or twice, you know that it will be created along with all other vars from that function before any other code in the function.
      Here's where knowing well the proper scope for your variables is important to keep track/plan.
      Side note:
      Between const & let:
      IMHO, I use them as variable-type identifiers, if I have a const someVar I know it's value is 'secure', constant. At the same time when I see let sumVar, I know it's scope is limited to the block and that it is probably doing some calculation or tracking a value that varies.
      ps: this was much longer than I intended, I hope it helps.

  • @glialcell6455
    @glialcell6455 10 ปีที่แล้ว

    Most of these aren't exclusive to Javascript, and this video could definitely have been reduced to a 5 second list. Also, the intro was kinda' creepy (not much offense intended).

  • @lionpersia
    @lionpersia 7 ปีที่แล้ว +1

    OMG...

  • @harvesterofsorrow731
    @harvesterofsorrow731 10 ปีที่แล้ว

    Difficult to follow.

  • @goldilockszone4389
    @goldilockszone4389 8 ปีที่แล้ว

    Should I learn Javascript or Python ?

    • @goldilockszone4389
      @goldilockszone4389 8 ปีที่แล้ว

      Mostly mobile Apps

    • @goldilockszone4389
      @goldilockszone4389 8 ปีที่แล้ว

      thank you. I have heard one can make mobile app with Javascript also ?

    • @goldilockszone4389
      @goldilockszone4389 8 ปีที่แล้ว

      thanks. I have also heard that the world is moving towards isomorphic programming and JAVASCRIPT due to its ubiquitous nature can act both in the client and the server side ( aka NODE.Js). Considering this isn't it better to learn JS ( eg MEAN stack) and become a master of all with one language instead of learning SWIFT, PYTHON, JAVA ?
      ref - nerds.airbnb.com/isomorphic-javascript-future-web-apps/

    • @goldilockszone4389
      @goldilockszone4389 8 ปีที่แล้ว

      You can always build and app on JS via mobile frameworks like IONIC.

    • @goldilockszone4389
      @goldilockszone4389 8 ปีที่แล้ว

      Got it ! how does one know that one is proficient in it ? I have already started learning JS basic and have got a hang of JQuery ( not all libraries) and some bit of object orient javascript. I am learning via treehouse