5 Must Know JavaScript Features That Almost Nobody Knows

แชร์
ฝัง
  • เผยแพร่เมื่อ 23 ก.ค. 2024
  • 🚨 IMPORTANT:
    JavaScript Simplified Course: javascriptsimplified.com
    JavaScript is a vast language with tons of features and it is impossible to know them all. In this video I will be covering 5 features in JavaScript that nobody knows but are incredibly useful.
    📚 Materials/References:
    Web Dev Roadmap: webdevsimplified.com/web-dev-...
    Nullish Coalescing Article: blog.webdevsimplified.com/202...
    Optional Chaining Article: blog.webdevsimplified.com/202...
    Object Shorthand Article: blog.webdevsimplified.com/202...
    Async Vs Defer Loading Video: • What Is The Fastest Wa...
    Async Vs Defer Loading Article: blog.webdevsimplified.com/201...
    🌎 Find Me Here:
    My Blog: blog.webdevsimplified.com
    My Courses: courses.webdevsimplified.com
    Patreon: / webdevsimplified
    Twitter: / devsimplified
    Discord: / discord
    GitHub: github.com/WebDevSimplified
    CodePen: codepen.io/WebDevSimplified
    ⏱️ Timestamps:
    00:00 - Introduction
    00:41 - Nullish Coalescing
    04:37 - Styling Console Log
    06:19 - Optional Chaining
    12:45 - Object Shorthand
    14:55 - Defer/Async Loading
    #JSTips #WDS #Top5JS

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

  • @dealloc
    @dealloc 3 ปีที่แล้ว +144

    For the first one, just use default assignment for the arguments (e.g. `calculate(taxes = 0.05, description = "Default item")` - This only uses the default value if the value is `undefined` and not for `null`, which may be want you want for most cases, given the difference of meaning that they have, rather than treating them the same. This avoids a lot of unexpected behaviors and is more likely to throw type errors or invalid values at you so you can find and correct it quicker.
    You can also use object destructuring in arguments with default values, like `calculate({ price = 0.05, description = "Default item" } = {})`. Default assignment makes it more readable and behave more consistent with ECMAScript norms with regards to undefined/null values.

    • @C.Ezra.M
      @C.Ezra.M 2 ปีที่แล้ว +2

      The problem with the first way is that, according to the ECMAScript spec, a SyntaxError will be thrown if the function body has a "use strict" directive.

    • @miggu
      @miggu 9 หลายเดือนก่อน

      I am still surprised at how underused destructuring is everywhere in javascript today in favour of dot notation. I never understood why it never caught on. product.title, product.price? does that help with the readability or is it useless repetition.

  • @JasonBoyce
    @JasonBoyce 3 ปีที่แล้ว +209

    The person?.address?.street is going to save me SO MUCH time in React

    • @neuralwarp
      @neuralwarp 3 ปีที่แล้ว +7

      Or you could just use your classes and datatypes correctly.

    • @suspendedchaos
      @suspendedchaos 3 ปีที่แล้ว +65

      @@neuralwarp yeah why use a feature that saves times

    • @vikivarun6122
      @vikivarun6122 3 ปีที่แล้ว

      Yea for me also

    • @vishal_kr_vishwakarma
      @vishal_kr_vishwakarma 3 ปีที่แล้ว +4

      I love you `?.`

    • @arunaravind6154
      @arunaravind6154 3 ปีที่แล้ว +7

      As dangerous as using 'goto' in a high level language. Almost all of these will cause hard to debug bugs sooner or later . Just use a strongly typed alternative.

  • @SergeyNeskhodovskiy
    @SergeyNeskhodovskiy 3 ปีที่แล้ว +37

    13:40 it's striking through "name" because it assumes you're writing for a browser and the "name" property exists in the global scope (on the "window" object). It's trying to save you from confusion, although AFAIK this doesn't in fact create any problems.

  • @73dines
    @73dines 3 ปีที่แล้ว +328

    03:05
    Kyle: you're not use to see question marks in javaScript
    Ternary operators: are we jokes to you?
    :D

    • @gdolphy
      @gdolphy 3 ปีที่แล้ว +4

      X = (assert something) ? Val1 : (assertion 2) ? Val2 : val3;

    • @lexnastin9011
      @lexnastin9011 3 ปีที่แล้ว

      yes,,, so true!

    • @lorddoomer7271
      @lorddoomer7271 3 ปีที่แล้ว +2

      This ?? thingies is amazing...

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

      and its basically a ternary operation.
      object ?? val1
      looks very similar to
      object? (as in, does it exist) ? val1 : val2

    • @deViant14
      @deViant14 3 ปีที่แล้ว +2

      language = 'Python' if is_readable else 'Javascript'

  • @KeganVanSickle
    @KeganVanSickle 3 ปีที่แล้ว +25

    I'm proud to say that I knew and use these features nearly every day. Great video Kyle, I really like your channel!

  • @quickcodingtuts
    @quickcodingtuts 3 ปีที่แล้ว +188

    The console log styling blew my mind. You learn something new every day I guess...

    • @MrBroady02
      @MrBroady02 3 ปีที่แล้ว +14

      I found out when I opened devtools in facebook, they had a warning not to paste any malicious code into the console.

    • @darxoonwasser
      @darxoonwasser 3 ปีที่แล้ว +6

      @@MrBroady02 Same with discord but I didn't know how it was done

    • @Manny-mc3rx
      @Manny-mc3rx 3 ปีที่แล้ว +2

      Does he have a full JavaScript course on udemy? If so can someone pls help me with a link or his name on udemy?

    • @darxoonwasser
      @darxoonwasser 3 ปีที่แล้ว

      @@Manny-mc3rx I don't think so but on fireship.io

    • @Levi_OP
      @Levi_OP 3 ปีที่แล้ว +1

      Another cool thing you can look up is that you can put images in the chrome console

  • @Ayomikun
    @Ayomikun 3 ปีที่แล้ว +108

    Even when I think I already know this stuff, I always learn something new. Had no idea you could use optional chaining with functions and arrays, though I'm not a huge fan of how it looks 😅

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

      I'm surprised he didn't put it in the video, but console.dir() is another great feature. Makes it super easy to see heavily nested JSON in the terminal

    • @Ayomikun
      @Ayomikun 3 ปีที่แล้ว +1

      @@Rogue_Art Oh interesting, I'll be giving that a go!

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

      Lol, same thoughts. I thought there would be some new syntax for function call like that:
      function?()
      or array index
      array?[571]

    • @SirusStarTV
      @SirusStarTV 3 ปีที่แล้ว

      And I don't like private property syntax like #privateProp, "private" keyword or _privateProp would be much better

    • @NM-vi5pf
      @NM-vi5pf 2 ปีที่แล้ว +1

      @@SirusStarTV execution function by "function()" is just a sugar syntax for "function.call(thisArg, args)" so it's quite the same as with object properties "function?.call(thisArg, args)" -> "function?.()"

  • @Jshanks21
    @Jshanks21 3 ปีที่แล้ว +2

    Came for optional chaining and ended up staying for the full suite. All super valuable, great work and thank you!

  • @reyanrahman
    @reyanrahman 3 ปีที่แล้ว +95

    U can't imagine how happy I am knowing that I already know and use all these features except the console styling thank you so much I have learned a lot from ur channel

    • @christianalejandro4963
      @christianalejandro4963 3 ปีที่แล้ว +6

      Felt the same thing. Console.log styling was jaw dropping.

    • @subhashbeniwal4973
      @subhashbeniwal4973 3 ปีที่แล้ว

      same

    • @christianalejandro4963
      @christianalejandro4963 3 ปีที่แล้ว

      I have to add that I still haven't used it :P

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

      Same boat. I was aware of it though because many sites like discord will spam styled logs to get people from not using the devtools if they're not tech savvy.

  • @bradchellingworth5973
    @bradchellingworth5973 3 ปีที่แล้ว +4

    When I discovered optional chaining in Ruby a few years ago it literally changed my life. So happy to see it eventually made it to JS

  • @nathanbustamante1525
    @nathanbustamante1525 3 ปีที่แล้ว

    Optional chaining is exactly what I needed. Been struggling with a desktop app breaking because we were getting unexpected nulls. Thank you!

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

    I have to admit, I thought it would be mostly things I was familiar with but I wanted to make sure so I gave it a watch. All five items were new to me! Teaching me both ES and to not make assumptions about my current knowledge. Thank you!

  • @multiwebinc
    @multiwebinc 3 ปีที่แล้ว +5

    If you're a React developer, note that Babel 7.8.0+ supports the new ECMAScript 2020 features by default, which includes nullish coalescing (??) and optional chaining (?.). So you can use them in your project without worrying about legacy browser support.

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

    13:30 This is really good to use if you need to build deeply nested complex objects (maybe to turn into JSON).
    You can build it inside out by building the inner most objects, then just including them in their parent, all the way up to the root element.
    Much more readable and flexible as every sub-object has a reference, and you avoid the Xmas tree of deep nesting.

  • @MiSt3300
    @MiSt3300 3 ปีที่แล้ว +1

    Wow the console log styling is going to be helpful, and adding that '?' check before accessing a variable of something really saved me.
    Thanks so much Kyle!!

  • @sudarshankj
    @sudarshankj 3 ปีที่แล้ว +2

    Very clear explanation! Thank you.
    Nullish Coalescing and Optional Chaining, my 2 new tools ✌🏼

  • @kosemekars
    @kosemekars 3 ปีที่แล้ว +16

    Optional chaining saved my life numerous times.

  • @yousufkhan2909
    @yousufkhan2909 3 ปีที่แล้ว +37

    never seen or heard styling console log before. you are gem.

    • @ricko13
      @ricko13 3 ปีที่แล้ว

      useless but ok

    • @justnathan7155
      @justnathan7155 3 ปีที่แล้ว

      @@ricko13 color coding

    • @spartaboss8387
      @spartaboss8387 3 ปีที่แล้ว

      @@ricko13 vbvlhbbvvbbvkbgvphvbbbb)))?:-::;::?--?-;;:::;::::-::;;::::?-?-::-:;::;:::?(-?0:?)-)-??);::(;;:--:-:;-;:;;::;-?::/;;:-;:;-:?:?-)!?;??;?)?))????-?:;-:-)-:-:);;--::-:!:;::::::::::(;--:;)--:!:
      Vmlbvbbvvmgggklgbgvvvvbhgvvgbnbbvvvvkvvvg
      Gggvkvvvvphglbgvlbmmmmmvlhvvlvkmjvvvbmbbvvgvvhkvvgvhvgbggbbvvbvbbgvvvmvvklmmkvkggbgvgvvgvvbpvvgvghvvv
      Bvmvgjvggkggvhhh
      Bbvbvvvvb
      CclvnmgvgvvvpvvgvgggmvvvvbggvvvgpmkgvvbkkvbmmllmnblkglhbbvkvvvvvmgggvvvvvgbvngvvbgvvvbxvmvmkmbvvlvvbvvbvvvgvgbvgbvvbvvhvbvvvhgvvbvvpvgvbvgbvbbvvlfkkmmmmllkmmhbgvbhbbvmvbvgbgvvbvhggvvbbvvbbgvgvvmghmbvmbggmmHvlkklhmvhvjvvbbbbvvvgvmvbvhvggvvgvvpbvgpbvmvgvvmgmbmkvgkmmmmkmvvhbvvbcvvggvgvvvbvvvvvvbvbbgvcvvvvvvvvvvmvvbgvvbvmvblmlmhmkmmmvlmmkmmmlvvvgmgvhvvkvbvvbghvbvvvvmggvbvbvgvvvvbvvggvvvmpvvmvvhvvvgkmhlkbmmmmxpmkmclbgggg
      Gbvvvvvnbbgvbvvgbgvvvvvvvgvgvhkgvvmvpvpvbbmkbmmvvmmmlmlmmmmlvlhbvvhvbvkgvvvvbhvgppvvbvggpvbvbgbvmhggckvbvmvmvvvkgvpmvvgvvhkckkkvmmvkvmmkvvmvbvvvvvgbvnbgvvggvvhbbgvbvvvbhmlbbvbghvkvggpgvbvkgvpgbhbghbhmlgmlmmlvvvgvvvvbvhvvvvvvvvhvvgv bvbvvvvvpkvmgvmmlmvhhbvvhbbvVgbvvbvvvbbvvbbvbbbmhvgbvvvbbmhbpmlglkgmvvbvbbvvvgbbvbbvvbvvhvvmbvvhpvbbkg
      Gbmvhvhgkmmmmlklgvbvvlgvvbvbvvvvvvvvvvvvmpvgvvcbbnjkmkmkhbmmmmmbvkvvnmbvvvvvvggvggvvvvvppbbbcvhmmmmlkbbbbvbhbgvmvbmvvvhvbbvmvkbmmmmvbpvvlggvvvvvvvvbvgvm bvmvmvpbknkvmbmmmlmmmmccbvhvbbvvbmvb
      Bgvvpvvbpgvvpbbvv
      Hmv
      Mkbmvvglcmvpgvph
      Gvv
      Ggvbvvvvgmvvvvgvgvvvjvpvgpvgvvgvvvgmhg lkmvmlmvgvbvv bb bb bb bb bb bb bb v
      Vgbvggkvvvbvpv

    • @imagineeelego
      @imagineeelego 3 ปีที่แล้ว

      ive seen it, if you load pixi js in your project you will see a cool box in your console

    • @mikethegamedev
      @mikethegamedev 3 ปีที่แล้ว

      @@spartaboss8387 ??????

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

    All of these tricks were incredible... hats off!
    Thanks for spreading a little wisdom over us all!
    These were all pretty neat tricks I can see myself using in the future.
    Can't wait for more!

  • @juniordantas02
    @juniordantas02 3 ปีที่แล้ว +1

    I thought it was going to be a useless video with stuff I already know. But it turns out most of the features in the video it could have helped me solve problems right yesterday. Thank you so much.

  • @novailoveyou
    @novailoveyou 3 ปีที่แล้ว +5

    Thanks for showing those!
    Optional chaining looks really interesting to me however I have so many question on what are the caveats like
    How does it affect debugging? Because previously JS would tell you what went wrong and throw an error, and now it'd just go through and you might not even know something went wrong. I can see this being a huge debugging issue
    How does it work under the hood? Does it just do a regular if(!null && !undefined) check for you right in place where you did ?. or does it work somehow differently?
    What are performance hits on this? Does it slow down our code and if yes then how bad?
    What are the benefits of using this with TypeScript if there are?
    Would be great to have answers on those, I'm going to research

  • @cheat200
    @cheat200 3 ปีที่แล้ว +31

    You might run into some "Edge" cases... Nice one!

  • @ananwolf
    @ananwolf 3 ปีที่แล้ว +1

    I’m a beginner in JavaScript and enrolled in boot camp so watching your videos are super awesome and cool! Subscribed!

  • @md.siddiq7165
    @md.siddiq7165 3 ปีที่แล้ว

    Thanks Kyle. Loved the video. That optional chaining is awesome ❤️

  • @AdADglgmutShevanel
    @AdADglgmutShevanel 3 ปีที่แล้ว +34

    I'm going to have the most beautiful console logs from here on out

  • @tech-andgar
    @tech-andgar 3 ปีที่แล้ว +7

    Summary:
    Nullish Coalescing: c = a || b; /=>/ c = a ?? b;
    Styling Console Log: console.log(var, CSS_1, CSS_2 ); // CSS_1: 'font-weight: bold; color: red', CSS_2: 'color: green'
    Optional Chaining: console.log(obj?.existMethodOrProp);
    Object Shorthand: a=1; b=2; const obj = {a, b}; console.log(obj) // {a:1, b:2}
    Defer/Async Loading: // download js, awaiting download html and execute js

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

    Your passion for web development is really contagious, Kyle! Just randomly watching your videos and I already love JS :)

  • @graemekalb2292
    @graemekalb2292 3 ปีที่แล้ว

    Needed the nullish coalescing operator today and immediately thought of this! Thank you

  • @zraakuladann3946
    @zraakuladann3946 3 ปีที่แล้ว +426

    For someone who comes from C++ & Java:
    You skipping semicolon hurts me deeply.

    • @LilMartyFarty
      @LilMartyFarty 3 ปีที่แล้ว +68

      It still hurts me even though I started with js

    • @TheNewton
      @TheNewton 3 ปีที่แล้ว +13

      Javascript has automatic semicolon insertion, not foolproof.

    • @aravindmuthu95
      @aravindmuthu95 3 ปีที่แล้ว +18

      @@TheNewton That's the code editor extension, JS totally works without the semi

    • @jsonkody
      @jsonkody 3 ปีที่แล้ว +29

      Actually semicolons are fkng redundant trash. By using them you do the machines work.
      If you write all your code on one line you MAY write them so the code work but then you probably shouldn't write any code at all.

    • @jsonkody
      @jsonkody 3 ปีที่แล้ว +4

      Look at Golang. Even Ken Thompson realized this deep truth ;)

  • @yksnidog
    @yksnidog 3 ปีที่แล้ว +11

    "name" is a javascript keyword. That's why you shouldn't use it as a name ("identifier") for a variable.
    It is an attribute of functions which holds (Surprise, surprise!) the name of this function.
    So the command Func1.name will give you Func1 if Func1 is a function...
    Also it can be useful when used aside set, get, bind or classes.

    • @j0code
      @j0code 3 ปีที่แล้ว

      function names are written in lower case, not Upper Case. (unless it's an object constructor)

    • @yksnidog
      @yksnidog 3 ปีที่แล้ว

      @@j0code Yes and how you write it is said by a table of stone. In germany we write names and things in upper case (which is in english by the way not written upper case itself). I know we are not the entire world but it is the natural behavior all around me. And surprise again: Func1 will work. It worked in Netscape Navigator, Mozilla Browser, Firefox and now in Chrome. We can make things complicated or use the time for the better good, shouldn't we?

    • @SealedKiller
      @SealedKiller 3 ปีที่แล้ว

      It's not really a keyword. It's just a property of the function.
      The reason it's crossed out is because it's a global variable in the browser that's a property of the window object.

    • @yksnidog
      @yksnidog 3 ปีที่แล้ว

      @@SealedKiller a keyword is a word crossed out because it is used. So why exactly is a property identifier not a keyword? 8-)

    • @SealedKiller
      @SealedKiller 3 ปีที่แล้ว

      @@yksnidog Because it's a global variable that's used by the window object. When you assign something to the variable 'name' it assigns it to window.name. It's not a keyword, it's not reserved. It's just an identifier.

  • @shantanu0707
    @shantanu0707 3 ปีที่แล้ว

    I really needed that Optional Chaining for a React project I'm doing. Blew my mind.

  • @ronidey7100
    @ronidey7100 3 ปีที่แล้ว

    Thank you so much for letting me know about the optional chaining 👍❤️

  • @NecaVideo
    @NecaVideo 2 ปีที่แล้ว +15

    One more thing that you forgot to mentioned is the shorthand for casting string to number.
    let price = '0.05'; price = +price; now price has number type. It's useful sometimes.

    • @BostYT
      @BostYT ปีที่แล้ว

      I use price = Number(price)

    • @messerjack8559
      @messerjack8559 ปีที่แล้ว

      this also works :P price = '0.05' * 1. Because you can not multiply a string, JS now it must be integer

  • @keydib8913
    @keydib8913 3 ปีที่แล้ว +199

    Am I the only one who is this excited every time he release new videos

    • @MuhammadAdnan2.0
      @MuhammadAdnan2.0 3 ปีที่แล้ว +4

      Maybe...

    • @BO-nn9up
      @BO-nn9up 3 ปีที่แล้ว +1

      here same from Korea

    • @eseseis7251
      @eseseis7251 3 ปีที่แล้ว

      Keydi, you need something, something you got the illusion you r getting with each video

    • @keydib8913
      @keydib8913 3 ปีที่แล้ว

      Ese like what?

    • @domination3428
      @domination3428 3 ปีที่แล้ว +1

      @@keydib8913 Yes, because you are girl and we are not gays =)

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

    These are so helpful and wonderfully explained. Thank you so much!

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

    Nullish coalescing and Optional chaining are just Killer-features. This video is a blessing. Thank you !

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

    Can you add the information about the ECMAScript versions when each of the mentioned possibilities became available please?

  • @alekhshah32
    @alekhshah32 3 ปีที่แล้ว +17

    Dude this is amazing. This helps make me write clean, error-free code with so much more confidence. Thanks for such great content.

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

    we really know a comprehensive video to show us all the hacks tips and features that will make our js code short clean and robust.
    Great Video!

  • @aelfar7533
    @aelfar7533 3 ปีที่แล้ว

    Wow, amazing job bringing us these features, love them lots. Thanks!
    I'm still waiting for Master of Puppets guitar shredding haha.
    Keep it up, we love you man!

  • @AP-pm9qy
    @AP-pm9qy 3 ปีที่แล้ว +3

    I saw the thumbnail of isCrazy() and I was fully prepared to see a function called that. Nothing surprises me in JS anymore.

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

    I recently discovered optional chaining and my God my life is so easy now.

  • @oldclient
    @oldclient 3 ปีที่แล้ว +2

    Project C# was designed to mimic Java. Over the years the language evolved so much that I see almost every modern language is using many C# ideas, like:
    1. Lambda expressions = Arrow functions;
    2. WPF Grid ~= CSS Grid;
    3. TPL Lib/Async = Async/Await in JS;
    3. Syntactic sugar = the stuff mentioned in your blog and more.
    Now, in my opinion, is time to add another ultimate C# technique - pattern matching, like:
    if (kyle is Person person && person.address != null){ //we have the assign and check in one expression
    person.print();
    printPersonStreet(person);
    }

  • @jaimeandrescarcamosepulved2456
    @jaimeandrescarcamosepulved2456 ปีที่แล้ว

    Awesome!! thank you. Taking notes.

  • @vquilon
    @vquilon 3 ปีที่แล้ว +12

    Why dont use parameters default value on function signature?, I mean is like python kwargs but in javascript you can assign a default value if not passed

    • @can_pacis
      @can_pacis 3 ปีที่แล้ว

      That's just the way he presented it, you can use it anywhere with any variable not just function parameters.

    • @MatthewWeiler1984
      @MatthewWeiler1984 3 ปีที่แล้ว +1

      ​@@can_pacis That's not what @vmalvoq meant.
      He meant why not just use default parameter values.
      function calculateCost(
      itemCost,
      taxRate = 0.05,
      itemName = 'unknown item'
      ) {
      const totalCost = itemCost * (1 + taxRate);
      console.log(itemName + ' costs $' + totalCost);
      }
      The main difference is that the default parameter value is only used if the parameter value is undefined.
      In my above example function, if the taxRate or itemName are null, the default value on the parameter will not be used.
      > calculateCost(100, 0.07, 'my item');
      > my item costs $107
      >
      > calculateCost(100, undefined, undefined);
      > unknown item costs $105
      >
      > calculateCost(100, undefined, '');
      > costs $105
      >
      > calculateCost(100, null, null);
      > null costs $100

    • @can_pacis
      @can_pacis 3 ปีที่แล้ว +1

      @@MatthewWeiler1984 I can't exactly remember what I was talking about and I just don't want to rewatch this video but it looks like you are right, I'm not sure. If so, thanks for correcting and have a good day

  • @noctislupo93
    @noctislupo93 3 ปีที่แล้ว +95

    There are at least 2 errors in the video:
    - ?.() doesn't check if is a function
    - ?.[] don't check if is an Array.
    The ?. operator only checks null and undefined

    • @RameenFallschirmjager
      @RameenFallschirmjager 3 ปีที่แล้ว +4

      Nice catch. You have a sharp mind!

    • @nikhilmwarrier7948
      @nikhilmwarrier7948 3 ปีที่แล้ว

      Yep. It's a nullish coalescing operator for methods

    • @noctislupo93
      @noctislupo93 3 ปีที่แล้ว

      @Michał Kasprzak this is because until JS3/4 (I'm not sure of the version name) there was no difference between array and object. Array was only object with numeric index, and not a different type

    • @KlausHott
      @KlausHott 3 ปีที่แล้ว +1

      CoffeeScript did this back in the day

    • @altansipdrae2759
      @altansipdrae2759 3 ปีที่แล้ว

      @@noctislupo93 aren't they still very similar? you can still access an object attribute using brackets [], like it was an array of key => value, keys being string. I use that a lot to access object attribute dynamically through the use of a string function parameter

  • @capm_diealone
    @capm_diealone 10 หลายเดือนก่อน

    These are great tips that a lot of experienced devs are very familiar with, so it’s great to present them to those that are newer to JS. I will say though that I’ve watched a few of you videos, and the fact that you don’t terminate your lines with a semicolon drives me absolutely up a wall.

  • @kirillvoloshin2065
    @kirillvoloshin2065 3 ปีที่แล้ว

    wow, I really run into the problem of undefined objects all the time! Thank you for the video!

  • @walterlol
    @walterlol 3 ปีที่แล้ว +16

    You could just do a default assignment with the first example. That's the cleanest way.

    • @yashchauhan5710
      @yashchauhan5710 3 ปีที่แล้ว

      But that won't do a check I guess

    • @Champagnerushi
      @Champagnerushi 3 ปีที่แล้ว

      Default assignment will only assign for undefined, not nulls

    • @walterlol
      @walterlol 3 ปีที่แล้ว

      @@Champagnerushi I know. But he is not using null.

    • @Solodam
      @Solodam 3 ปีที่แล้ว

      default assignments are "undefined"...
      And if you do set a default value yourself, VSCode will let you know what type is expected if you arent using typescript.
      so if you create something like function test ( arg = [] ) {};
      VSCode will tell you that arg is expected to be an array.

  • @Gastell0
    @Gastell0 3 ปีที่แล้ว +14

    This is great, but absence of semicolons bothers me deeply xD

    • @gosnooky
      @gosnooky 3 ปีที่แล้ว +1

      Semicolons are trash

  • @Tommy-jn9ps
    @Tommy-jn9ps 3 ปีที่แล้ว +2

    Kyle we need a story telling video or a debating video like the fang one. I really enjoy those.

  • @misterl8129
    @misterl8129 3 ปีที่แล้ว +1

    defer was the mindblowing for me, thank you!

  • @webster.
    @webster. 3 ปีที่แล้ว +19

    All features are same as in C#

    • @83hjf
      @83hjf 3 ปีที่แล้ว

      i miss linq

    • @bibi2900
      @bibi2900 3 ปีที่แล้ว

      You mean “stolen from c#”.
      In next js edition: “this” is “this” and not some random sh**.

  • @kuroexmachina
    @kuroexmachina 3 ปีที่แล้ว +19

    oh damn
    optional chaining is finally out
    tbh just use typescript

    • @arnerademacker
      @arnerademacker 3 ปีที่แล้ว +2

      Or maybe don't.

    • @arnerademacker
      @arnerademacker 3 ปีที่แล้ว

      ​@AngryJoeIsRacist Super Racist Typescript is not an easier version of JavaScript. It's a superset of JavaScript, meaning all JavaScript is valid Typescript.
      I'd argue you shouldn't use Typescript until you have understood why you are using it and how vanilla JavaScript approaches the same issues. Because otherwise you're adding a lot of complexity and overhead for no reason.

    • @arnerademacker
      @arnerademacker 3 ปีที่แล้ว

      ​@AngryJoeIsRacist Super Racist You said - and stop me if I quote you incorrectly here - "you can make life harder on yourself" in response to my statement to "perhaps [not use Typescript]". Implying - and I will use simple deduction here, stop me if you have trouble following - that somehow there is an added cost to using Vanilla JS.
      I made arguments as to why that isn't the case.
      1) JavaScript is easier. Which you just agreed on. So that's not the added cost.
      2) JavaScript is valid TypeScript. A vast majority of issues you encounter in Vanilla JS you encounter in TypeScript. That's why it's relevant that TypeScript is a superset. (And comparing programming languages that literally contain the exact same vocabulary and grammar to spoken languages that do not is a false equivalent. But I'm guessing you know that.) So more issues in Vanilla JS is also not the added cost.
      3) Typescript adds overhead and complexity, because it adds additional grammar (that's the complexity part) and requires you to use a lot of the additional grammar to get a use out of Typescript (that's the overhead part). That would mean Vanilla JS is both lower in complexity and lower in overhead. So that's not the added cost.
      Now that I have cleared that up for you, since apparently that was necessary, please, enlighten us as to why Typescript is supposed to "make life easier" instead of flailing at my comment line by line but provide no arguments of your own.

    • @arnerademacker
      @arnerademacker 3 ปีที่แล้ว

      ​@AngryJoeIsRacist Super Racist See, now you're actually making arguments. Thank you. That's all I wanted.

  • @chukwumaohuabunwa
    @chukwumaohuabunwa 3 ปีที่แล้ว +1

    I am grateful that you decided to teach web development. I learn something new and cool every time.
    Thank you and God bless.

  • @IronTeddyBear
    @IronTeddyBear 3 ปีที่แล้ว +2

    We've had these newer syntaxes in C# for a while, it's nice to see JavaScript has it too.

  • @joshr3739
    @joshr3739 3 ปีที่แล้ว +12

    As an FYI, from the Mozilla docs:
    "If there is a property with such a name and which is not a function, using ?. will still raise a TypeError exception" - basically if you do kyle.print?.() and print exists in the object but is not a function it will throw an error.

  • @Ryan86me
    @Ryan86me 3 ปีที่แล้ว +17

    function calculatePrice(price, taxes = 0.05, description = "Default item") {

    • @aashiqahmed5273
      @aashiqahmed5273 3 ปีที่แล้ว

      yup, default props,but it does not works for null or empty values

    • @dealloc
      @dealloc 3 ปีที่แล้ว +1

      @@aashiqahmed5273 Which I'd argue is a good thing. Null shouldn't be treated as `undefined`. They are inherently different things and should often be treated as such. Passing null into places will show you that something is incorrect much faster than replacing it with a default value.

    • @can_pacis
      @can_pacis 3 ปีที่แล้ว

      @@aashiqahmed5273 they are not props they are parameters

  • @Linuxdirk
    @Linuxdirk ปีที่แล้ว

    I love the nullish coalescing operator. I already used it in production multiple times to replace pretty much all of the "workaround code".

  • @nativeKar
    @nativeKar 3 ปีที่แล้ว

    Hey Kyle, love your content. These videos help me so much not only during my day-to-day job but also at some interviews. Can you please (pretty please) make some redux related videos?

  • @arthurdewitte4521
    @arthurdewitte4521 3 ปีที่แล้ว +6

    For the one with the default argument values, did you know you could just pass them like this?
    function calculatePrice(price, taxes = 0.5, description = "Default item") {
    ...
    }
    This will do the exact same but it will allow you to not even have to specify the last two arguments, as it will take the default value.
    For example, you could do this: calculatePrice(10); // which is valid but calculatePrice(10, 0.75); is also valid!

    • @BostYT
      @BostYT ปีที่แล้ว

      That's what I was thinking! His way is inefficient.

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

    Woah, I knew all of those! 🎉

  • @anhqui19822011
    @anhqui19822011 3 ปีที่แล้ว

    Thank Kyle for very useful video. It helps me a lot!

  • @BarrettGamingHD
    @BarrettGamingHD 3 ปีที่แล้ว

    Really cool to see the optional chaining operator out of the box with JavaScript now, very useful

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

    Can't you just define default values in the function definition like this: calculatePrice(price, taxes=0.05, description="Default item") {....?

    • @reinieltredes8306
      @reinieltredes8306 3 ปีที่แล้ว

      No

    • @peybro
      @peybro 3 ปีที่แล้ว +1

      @@reinieltredes8306 ok thanks for that detailed explanation

    • @reinieltredes8306
      @reinieltredes8306 3 ปีที่แล้ว +1

      I'm a beginner. I tried your sample and... It works. Thanks dude

    • @reinieltredes8306
      @reinieltredes8306 3 ปีที่แล้ว +1

      @@KalmeMarqTG tried on pure js. It works too

  • @Hearrok
    @Hearrok 3 ปีที่แล้ว +4

    Video: "New features in JS..."
    Me: Yeah... I'm stuck in working with ES5 in corporations :/

    • @KinSlay1337
      @KinSlay1337 3 ปีที่แล้ว

      Transpile with babel

    • @Hearrok
      @Hearrok 3 ปีที่แล้ว

      @@KinSlay1337 unfortunately it creates less readable and maintainable code for the person that might need to update something in the future :(
      So even if it technically works, it's not acceptable for maintainability.

    • @KinSlay1337
      @KinSlay1337 3 ปีที่แล้ว

      @@Hearrok you can always keep the untranspiled code to be maintained but I guess people where you work are too set on old practices if it's not an option

    • @Hearrok
      @Hearrok 3 ปีที่แล้ว

      @@KinSlay1337 It's not the people it's the system engine interpreters that can't handle higher versions. Also having two copies of the same code but in different versions would add even more complexity to everything. It's not that hard to just write code with older styles. It's just that it would be nice to have things like arrow functions x)

  • @95jugal
    @95jugal 3 ปีที่แล้ว

    Thanks for sharing these new features. Please keep creating such informative videos. 👍🏼

  • @MB-zj3er
    @MB-zj3er ปีที่แล้ว

    defer -- wow! Worth an entire video. How did I not know this? Thank you!! time to go delete a lot of load functions...🤦‍♂

  • @Springfielde
    @Springfielde 3 ปีที่แล้ว +4

    So we handle "undefined" by writing code that doesn't throw error for it... :D

  • @fredi1505
    @fredi1505 3 ปีที่แล้ว +6

    What I understood was if you run into errors in javascript just throw in a '?'

  • @leanderhughes
    @leanderhughes 3 ปีที่แล้ว

    Very useful Kyle. Thank you!

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

    so i saw all these in code already and figured what they did, but it's good to have them explained now :D tyy

  • @narcissisticnarcissus4956
    @narcissisticnarcissus4956 3 ปีที่แล้ว +4

    Instead of console.log(), I ofter use console.table().
    So much cleaner.

    • @tochimclaren
      @tochimclaren 3 ปีที่แล้ว

      Or console.dir to extract info

  • @valdoimpalatorez
    @valdoimpalatorez 3 ปีที่แล้ว +6

    Stealing solutions from C# I see. :D

    • @cryptodapps3340
      @cryptodapps3340 3 ปีที่แล้ว +1

      I was about to say the same thing

  • @Wakedaddy87
    @Wakedaddy87 ปีที่แล้ว

    That optional chaining thing has been something that I have been trying to use, but ran into syntax issues. And this video showed me what I was doing wrong and I am definitely going to be fixing my code to use this now. Thanks!

  • @AniaKovas
    @AniaKovas 3 ปีที่แล้ว

    Handy, Thanks Kyle. Very clear explanations.

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

    I hate the && and || sintax because for me that should return a boolean like *taxes || 0.5* should return true or false

  • @frmcf
    @frmcf 3 ปีที่แล้ว +7

    6:45 Probably shouldn't have used your real address, Kyle...

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

    As a novice to Javascript, these tips are amazing. I'm especially fond of being able to apply css to console logs!

  • @DEVDerr
    @DEVDerr 3 ปีที่แล้ว +2

    In this nullish coalescing example - it is indeed good example to clearly show how does it work, but people please - in situations like this one, in commercial non-personal projects use default argument values instead.
    It will work completely the same, it's more readable and also provides you better developer experience by allowing you to check what the default value is by mouseover on function name in some IDE's like VSCode or WebStorm/PHPStorm, without needing to jump into the source code and analyzing where the heck the default value assign is

  • @adam.foster
    @adam.foster 3 ปีที่แล้ว

    Love your knowledge - great tips!

  •  3 ปีที่แล้ว

    Thanks a lot for the explanation of the new ecma script features. Video full of usefull information. Thumbs up

  • @arsengalloghlyan3688
    @arsengalloghlyan3688 2 ปีที่แล้ว +1

    10:45
    But I think if we use optional chaining for functions it only checks is our property defined, because if we pass a defined but non callable property before the question mark it will work but with an error.

  • @NicoHeinrich
    @NicoHeinrich 3 ปีที่แล้ว

    This video is pure gold. Thanks so much!

  • @skillzorskillsson8228
    @skillzorskillsson8228 3 ปีที่แล้ว

    i knew it was possible to style the console.log messages since i have seen many websites with styling in the console. But i had no idea how to do it... And i am not sure why i have not looked it up. This is pretty awesome actually. I am very happy that you shared this !

  • @alexanderkomanov4151
    @alexanderkomanov4151 ปีที่แล้ว

    Wow! So useful! Thanks a lot!

  • @Ricardoromero4444
    @Ricardoromero4444 3 ปีที่แล้ว

    I've seen object shorthand almost everywhere
    I didn't know nullish coalsescing, that's pretty useful

  • @excessreactant9045
    @excessreactant9045 3 ปีที่แล้ว

    That defer tag is so cool!

  • @AndreR241
    @AndreR241 3 ปีที่แล้ว

    Nice to see, that all the nice features of c# finally got ported to JavaScript as well.

  • @elliotsharpe5448
    @elliotsharpe5448 3 ปีที่แล้ว

    wow optional chaining has absolutely blown my mind, that is a massive problem solver.

  • @ericdimarzio5756
    @ericdimarzio5756 ปีที่แล้ว

    Thank you for such a great video!

  • @JulioDx3480
    @JulioDx3480 3 ปีที่แล้ว

    Awesome! Thanks for sharing.

  • @nabiismayilov2860
    @nabiismayilov2860 3 ปีที่แล้ว

    Thanks, your videos are very helpful 👍🏻

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

    Outstanding job, thanks!!!

  • @jennifershen4273
    @jennifershen4273 3 ปีที่แล้ว

    Thanks man! This is super helpful!

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

    your channel is money. learning so many new, useful things.

  • @TRUNKER76
    @TRUNKER76 3 ปีที่แล้ว

    these were all great. Thanks!

  • @pubgproentry2799
    @pubgproentry2799 3 ปีที่แล้ว

    Hi Kyel, Thanks for this video. This type of video very helpful. make more short video like this

  • @WhenImAloneI
    @WhenImAloneI 3 ปีที่แล้ว

    Thanks! Very helpful!

  • @DT2324
    @DT2324 3 ปีที่แล้ว

    Mind blowing tricks! Thanks for sharing!