Stop Using The '!' Bang Operator In JavaScript Unless You Know This

preview_player
Показать описание


🌎 Find Me Here:

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

"you might not want to bang that"

- Code Review comment

giantqtipz
Автор

Content is good but title is misleading. You gotta stop using "stop using"

fayas
Автор

The developer is responsible for making sure the program can handle any test case input properly. There is nothing wrong with using '!' as long as you understand what it does and it doesn't break you program. Also, this is another reason I advocate everyone to learn and use Typescript.

hizzie
Автор

Bad premise, and the title is somewhat misleading. There are some ppl that will take it at face value.

Don't stop using bangs. Use them well: when your predicate relies on evaluating ALL falsy values (false, empty string, 0s, NaN, undefined, null), which kyle implicitly pointed out later in the video.

As developers, we should know our tools very well, and use the right one for the job. Avoid parts of the language is bad work ethic as best.

lunify
Автор

If I put "-1" into the input box, the whole program will implode on itself.

multiwebinc
Автор

Being explicit is good practice, in my opinion. On top of preventing needless bugs like this, it also makes it easier to understand a *little* bit faster when you have to come back to something you did weeks later.

mattsmith
Автор

this little tips are actually as valuable as the long tutorials

babafemiolasunmade
Автор

Useful video, as usual. It bears mentioning that isNaN creates its own set of headaches and oddities, e.g. isNaN(null) is false.

brachypelma
Автор

"!user" is better if you don't want "user" to be the number 0, an empty string (there are probably more invalid values for "user" that "!user" returns true for that i'm not mentioning here) so 99% of the time you don't need to watch this video so the title is clickbait-ish but still the information presented is straight-forward and not misleading and i appreciate that

thesneakyturtel
Автор

Without music ur videos are just awesome

MDHasan-trnd
Автор

Bang operator and NaN function have no relation to each other, so I don't know how you can title this video as you did.
Oh yeah, it's just clickbait.

justSomeUserOnYT
Автор

Nice... This channel actually teaches how and why to program...

busyrand
Автор

This is a very specific scenario, if the value is not number then you won't have this issue.

diallomamadou
Автор

I dont even use javascript but i still watch these shorts. They are so clean and while I might not remember the code, as long as i know it exists, I can find it again.

dkznikolaj
Автор

I reviewed code of my junior today having this exact issue in his code.

SachinKumarSahu
Автор

Expectations: huge security leak that will shock me
Reality: 0 is falsey
The disappointment... :(

haim
Автор

Clickbait, didn't expect that from you.

heMech
Автор

I usually check this with != null (important: not !== null as that doesn't include nullish values like undefined) unless I know for sure the value isn't allowed to be 0 or ""

StabilDEV
Автор

It only depends on the expected result.
if we want 0 to be "Bad", then there is nothing wrong with the code

moneyalfonss
Автор

I'd drop the important term here. 0 is a falsy value. And Negating something truthy or falsy will result in either false or true.

Also, it's better everytime to use checks like `!== null` instead of `!= null` to be typesafe

YamiSuzume
welcome to shbcf.ru