Use THIS instead of IF-ELSE!

preview_player
Показать описание
#shorts #ternaryoperator
Рекомендации по теме
Комментарии
Автор

I love the ternary operator but I’ll be the first to admit, if the two statements are longer than a single variable, it’s probably best to use something else. I’ve made some pretty ugly React code with the ternary operator

bobthemagicmoose
Автор

Oh yeah my colleagues also high five me for using ternary operator chains for 15 lines and get rid of the cleanly written if else statements, although they tend to miss my hand and hit my head instead.

mapclickerandy
Автор

We normally only use ternary statements for when we are returning something. Otherwise it’s hard for other developers to read, especially if you chain ternaries 🤢

samplant
Автор

As cool as that is, readable code is better than short code.

jjlewandowski
Автор

All the junior/internship devs are mind blown now.

mokanin
Автор

Who is creating the content for this channel? Beginners who just started coding?

DEVDerr
Автор

Say what? No.

Instead, just set value to what it usually would be and only do an if... no else... and set it the other way. This print.

Ternaries are bad.

dusdnd
Автор

At least in this particular case, I'd actually suggest just using a function. Pretty much all optimizing compilers will inline the whole logic anyway, but "max(a, b)" (or anything similar) is way more readable and shorter than anything you can come up with otherwise, no matter IF-ELSE or whatever, especially when passed inside longer code. Same can be said for any other similar condition. Only one I'd use directly are null-coalescence operators.

Smaxx
Автор

I would rather use the normal IF-ELSE cus is easier to read and helps when another person of my team need to check it out.

eternalsoma
Автор

Even better, int max = Math max (a, b).

gbh
Автор

This type of coding shouldn’t be used often if ever other than to show off as it’s not easily readable and very confusing to quickly look and see what is happening. Something as standard and straightforward as an if else statement doesn’t need this

alexandersutter
Автор

Actually its the shortcoming of the language. Why not like console.log(maxof(a, b)).

Other option

Let x=a;
If(a<b) {x=b};
Console.log(x);

cmohanc
Автор

Sacrifices readability and clarity to save one line of code ?

darrenlefcoe
Автор

You have a great product and plenty to tell about it❤. Don't pretend to be a blog that teaches schoolchildren to code.😡

NirNiobis
Автор

I dont think this is a good idea on team project

methanesulfonic