JavaScript Fundamentals: Understanding the Ternary Operator

preview_player
Показать описание
The ternary operator allows you to reduce a conditional statement into a single line. Those just getting started with JavaScript sometimes do not understand the ternary operator. In this tutorial we go over it and provide examples.

For more resources on JavaScript:

Interested in some of our courses:

#javascript #AllThingsJavaScriptLLC
Рекомендации по теме
Комментарии
Автор

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! <3

hyfytale
Автор

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

robertm
Автор

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.

w.robert
Автор

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

nelsonjimenez
Автор

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

scottonanski
Автор

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...)

OatmealTheCrazy
Автор

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

zainafzal