JavaScript Fundamentals: Understanding the Ternary Operator

Поделиться
HTML-код
  • Опубликовано: 25 окт 2024

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

  • @hyfytale9577
    @hyfytale9577 5 лет назад +3

    You explain things thoroughly, and I can understand from a novice perspective! Your work is underrated and I hope more people find your videos to learn from!

  • @fabiansporer5797
    @fabiansporer5797 3 года назад

    Thank you, well explained!

  • @brunoamorim649
    @brunoamorim649 3 года назад

    great class!

  • @MrWardo2009
    @MrWardo2009 5 лет назад

    Thank you for this explanation!

  • @w.robert3844
    @w.robert3844 3 года назад

    Why does = work in the ternary operator? I thought === was for booleans and = was an assignment and == was for evaluation? I've been struggling with how/why boolean logic works/doesn't work in some instances and why it seems to have inconsistent expression throughout JS, depending on when/how/why it's used.

    • @AllThingsJavaScript
      @AllThingsJavaScript  3 года назад

      So the = used with these examples is an assignment operator. We are assigning a boolean to obj.pass. We just do it in a couple of different ways.

  • @nelsonjimenez7939
    @nelsonjimenez7939 6 лет назад

    Can you organize the videos from basic to advanced? Thank you and you rock!

    • @AllThingsJavaScript
      @AllThingsJavaScript  6 лет назад

      It may be a bit difficult to organize that way because they are so varied, but I do have plans to put together some additional playlists that may help. Beginning playlist and so on. Also, I have a tutorial page on my website that organizes them by different categories: allthingsjavascript.com/youtube.html

    • @nelsonjimenez7939
      @nelsonjimenez7939 6 лет назад

      All Things JavaScript, LLC thank you. Keep up ur work.

    • @anujupadhyay10
      @anujupadhyay10 6 лет назад +1

      ruclips.net/channel/UCRQhZGXC0WK85YRXl7nGX0wplaylists
      Here you go

  • @scottonanski4173
    @scottonanski4173 4 года назад

    Where did you define "min" in your code? I don't understand how "min" is being calculated.

    • @AllThingsJavaScript
      @AllThingsJavaScript  4 года назад

      The value for min is passed into the function when the function is called. (passOrFail(student1, 80);)

    • @scottonanski4173
      @scottonanski4173 4 года назад

      @@AllThingsJavaScript Ya, that's what I suspected, but I wasn't too sure. Thanks for clearing that up. This JavaScript stuff has me pulling my hair out.

    • @AllThingsJavaScript
      @AllThingsJavaScript  4 года назад

      @@scottonanski4173 Stick with it! It will start clicking.

  • @robertm4795
    @robertm4795 2 года назад +1

    Think the Ternary is easier to understand than a normal if statement.

  • @lulualmohtarif
    @lulualmohtarif 6 лет назад

    awesome, thank you.

  • @seenuvasanv
    @seenuvasanv 6 лет назад

    Thank you.

  • @OatmealTheCrazy
    @OatmealTheCrazy 6 лет назад

    For the last one, couldn't just just have had
    obj.pass = obj.score >=min
    Also, can you do a video about the comma operator?
    I saw this code to return the middle section of a string
    function getMiddle(s)
    {
    return s.substr(Math.ceil(s.length / 2 - 1), s.length % 2 === 0 ? 2 : 1);
    }
    However, I have no clue what the comma is doing. (I also have no clue what returning the 2 or 1 at the end do as well tbh...)

    • @AllThingsJavaScript
      @AllThingsJavaScript  6 лет назад

      Yes, you are correct. That would work great and would be simpler. I got too caught up in showing the ternary operator. :-)
      And yes I will plan on a tutorial for the comma operator.

    • @AllThingsJavaScript
      @AllThingsJavaScript  6 лет назад

      Here is a tutorial on the comma operator: ruclips.net/video/IvqdQB549KQ/видео.html

    • @OatmealTheCrazy
      @OatmealTheCrazy 6 лет назад

      Yeah! :D
      I actually saw it already, but I've been moving and planning like the last 3 weeks. Forgot to comment.
      Thanks much though!

  • @zainafzal6431
    @zainafzal6431 5 лет назад

    let passOrFail=(obj,min)=>{obj.result=(obj.marks>=min)?"pass":"fail";}