So glad you added that last line. Whenever i get to mentor programmers it's a big challenge to get them to let go of cute forms that make them look smart. It's hard on the ego to write code that looks as simple as it actually is.
After words “Lines… don’t work correctly”, I decided to pause and think what’s wrong, in a few seconds, I thought there is no handler for undefined and null values, so we need to add !! at the beginning. What a pleasant feeling to be right 😅
In my mind !! is the connonical way to cast to Boolean, and unary + is the connonical way to cast to Number. It's just easier to write, and not hard to read imo. More languages need a !! operator.
The actual solution is to follow the react docs which say you should always use a ternary like `array.length ? : null` instead of using && precisely because of this issue
@@Qbe_Rootthe guy in the video explained it. If it's a numerical value, it will be displayed. If it's null, undefined, or true/false (boolean) it won't.
@@Qbe_Rootyou commented on the short, so you must have watched it, and that’s the only thing he talks about. So I don’t understand how you missed the only thing he said.
2 potential reading properties of undefined errors from playlists.length and entities.length. Replace with ? instead. Now if playlists or entities is: 0, null, undefined, NaN, or false it will not display the components, otherwise it will. So assuming we have a playlists and entities of the proper type that has a .length method, it should only be false when its length is 0, true otherwise. Also, ensure that you want to potentially display both components at once, because they can both display.
My dude please continue making videos. There’s something different about how you explain, that just makes me think: Dang this guy will make some views in the long run
Or maybe you put code to render another page with cute image and text to recommend to upload the playlist if the legth is 0 on the very top so that code will be slightly become simple and can provide better ui/ux
Only a JavaScript Dev could try to reinvent the if statement and have it be this obtuse
You're mistaken. This is part of an "expression", not a "statement" meaning that "if" cannot be used here.
You cannot use if in a jsx expression.
@@sourtil7158lol what? Ok there are ternaries instead which are way more readable than bang-bang
@@robertsandiford6223you can use a ternary
@@robertsandiford6223 but doing "playlists.length !== 0"" is essentially an if
Just make the expression,
playlist.length > 0 && statemnt
&& before should work too
That one's the best. It reads exactly like what you want to actually do.
anyone who writes array.length && is a lazy and bad developer
@@essana3How else would you achieve this ?
@@chill89892it's a condition so devs should stop being lazy and provide and readable boolean. array.length > 0 ALWAYS.
So glad you added that last line. Whenever i get to mentor programmers it's a big challenge to get them to let go of cute forms that make them look smart. It's hard on the ego to write code that looks as simple as it actually is.
I was like "wow, that's dumb" until the very end, then I was laughing uncontrollably. Well played.
had us in the first half not gonna lie lmao.
The solution is to write > 0 at the end. It's easier to read and more obvious.
You missed the punchline.
@@keitsee I can see the importance of it, but given it is a stupid ass punchline, I elected to ignore it.
Love the last statement! 😂
Tbh it's far too common to use !!x && ... In JS frontends to be "hard to understand" by anyone with at least a few months of experience.
After words “Lines… don’t work correctly”, I decided to pause and think what’s wrong, in a few seconds, I thought there is no handler for undefined and null values, so we need to add !! at the beginning. What a pleasant feeling to be right 😅
that last bit got me. I pretty much stopped using this syntax because it's just harder to understand. I strive for simplicity wherever I can nowadays.
In my mind !! is the connonical way to cast to Boolean, and unary + is the connonical way to cast to Number. It's just easier to write, and not hard to read imo. More languages need a !! operator.
Awesome
Not gonna lie, you got me on the first half.
The actual solution is to follow the react docs which say you should always use a ternary like `array.length ? : null` instead of using && precisely because of this issue
i love this humor
ternary operator left the room
This is why JavaScript is only considered a scripting language and not a real programming language.
Thank you subscribed!
Explicit is better than implicit
Not in JavaScript it ain't
Isn't it easier to use {expression? Element : null} ? And not using weird sh*t just because it exists?
Even better {expr? JSX: }.
The && is not the problem here. Rather .length returns a number instead of a boolean
@@nithinsvarrier670 What's the problem with .length returning a number?
@@Qbe_Rootthe guy in the video explained it. If it's a numerical value, it will be displayed. If it's null, undefined, or true/false (boolean) it won't.
@@Qbe_Rootyou commented on the short, so you must have watched it, and that’s the only thing he talks about. So I don’t understand how you missed the only thing he said.
Finally someone gets it!
2 potential reading properties of undefined errors from playlists.length and entities.length. Replace with ? instead.
Now if playlists or entities is:
0, null, undefined, NaN, or false it will not display the components, otherwise it will.
So assuming we have a playlists and entities of the proper type that has a .length method, it should only be false when its length is 0, true otherwise.
Also, ensure that you want to potentially display both components at once, because they can both display.
I always prefer !== than !!, even if it's concise, I think in this case the explicit version is better.
I was going to criticize and then i heard the last statement and immediately agreed, nice vid bro
If we make it opaque enough, we will achieve total domination over the web. Probably.
Tbh it's a pretty common trick, nothing weird about it.
you can use
variablename ? : null
and no problems
I love your taste of humour 😂
Does anyone else like explicitly writing Boolean() instead of !! I think it’s more clear…? Any thoughts?
lol I love it
My dude please continue making videos. There’s something different about how you explain, that just makes me think:
Dang this guy will make some views in the long run
yes and he didnt leave a comment on the line above. job security!
Yea saw this in work did not understand then, now it's different thanks !!!!
You only need !! Btw !!!! Is redundant (but if you told me it was necessary in some scenario in JS, I'd believe you)
Or maybe you put code to render another page with cute image and text to recommend to upload the playlist if the legth is 0 on the very top so that code will be slightly become simple and can provide better ui/ux
Can't we use the Nullish Coalescent Operator here?
F*** JAVASCRIPT!!!
- Jim on a Tuesday afternoon
You worked hard to make that code. Why shouldn't future you work just as hard to understand it.
Nulish coalescing?
(playlists.length > 0) is crying in the corner
This isn’t the correct solution, the correct solution is: { conditional_statement ? true : null }
Obligatory "this wouldn't happen in Vue".
Nice
I would rather say don't be smart make code readble..
This is why people hate on React, because people use short circuiting and ternaries instead of if statements or a function like normal people
For me I try to archive all the logic before the return, so my JSX look more concise. Make it more readable to me.
using the eslint coming with the next.js keep yelling to not do this hhh idk why 😂 some other configs give the error too
Java vs Javascript
I like this but Eslint doesn't like it
Or you can use ??
5 sec before i got the 0 in my frontend wtf😂
playlist && playlist.length ()...
WTF that looks disgusting!
*last sentence*
I now remember why I hate webdev so much
I don't get it 😢
No. It doesn't make you smarter.
who doesn't use terniary operators here????
I don't disagree
imo more readable would be to just go `playlists.length > 0`, expresses what you mean more
Why would a logical AND operator return a div? JS is getting ridiculous 😩
Logical and returns the last truthy value or the first falsy value
it's called a short circuit of logical operators, has nothing to do with js
Or...... Use a better framework other than React
Why did he suicide ?
"He was making a code review of JS code"
Theme please..
Night owl
@@SamMeechWard Thanks.
The developers that don't know this are justing showing their lack of knowledge. I don't think this code is obtuse.
Because you should just use an if statement like a normal person
svelte > react
I fucking hate that JSX has lead to this god awful style of conditional rendering.
Fuzk react !
I prefer ternary. (? and : ) its clear and concise. Yet !! is cool 😎
playlists.length ? : nothing found
playlists.length > 0
svelte > react