Let’s play… Does your code suck? JavaScript Variables Edition

preview_player
Показать описание
Can you tell which code example is bad? Learn the subtle differences between variables in JavaScript by comparing let vs var.

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

You had me at "does your code suck".
Yes it does.

wlockuz
Автор

I mostly watch JS videos like this to continue validating why I don’t do web development.

TehKarmalizer
Автор

I've avoided using var without knowing what it does, but this really helped me understand, thanks!

tomasmartinez
Автор

Gotta love getting a runtime error for something which can be statically checked.

mylesbuckley
Автор

As a C/C++ guy that's a big "Holy shit people live like this?!" thing.

stevenclark
Автор

One of the most important lessons I learned early in my career as a SWE was that exceptions are good. The way they were taught in college, I felt like my job was to make sure nothing ever threw an exception and halted so I ended up with try/catches and log messages everywhere. No: if something goes wrong, you want to throw a good exception and let it break

evanbelcher
Автор

My personal go-to: use "const" for everything unless you need to mutate/set the value - then use let; even then consider using a new const if you can. Don't touch var like it's got an infection, I can't remember the last time I had to use it.

echoarts
Автор

Ah, the good old days of tricky js interview questions.

DK-oxze
Автор

i love to use const first and then adjust later with let, if needed (like in Rust, having immutability first and then adjust).

FloWoelki
Автор

"does your code suck"

I fixed a display issue the other day by adding a 0ms setTimeout.

cinderwolf
Автор

I can't tell because I can barely see the screen when YouTube puts buttons, labels, and other bs all around and blocks everything.

andreujuanc
Автор

I always use let ever since it became popular, but now I see why it got popular. I probably don't even realize how many headaces I've dodged

theilluminatimember
Автор

Thanks for letting me know before I end up messing up in the future 😅

micheledelzoppo
Автор

Praise Cthulhu, and his favorite programming language, JavaScript.

AnastasiyaSoyka
Автор

The error is not 'a is not defined' it will be ' can not access a before initialisation '

deepaksurya
Автор

Good one, I knew the var would hoist but I didn't know the value assignment would be executed after the log. I think even with a 100 years of JS experience one can be surprised from time to time.

ultragigachader
Автор

The TDZ is temporal, as opposed to scope-based. i.e. You can use your variable before it's defined in code order, as long as by the _time_ hou need it, it's been defined.

function logX() {
console.log(x)
// ☝️ refers to the x below thanks to hoisting
}

let x = 15

logX() // prints 15 just fine

kebien
Автор

Is your code JavaScript? Then it sucks.

jasonsimpson
Автор

I know nothing about javascript and just guessed that var does something funky based on my minimal Rust experience.

jorionedwards
Автор

It’s not the code that sucks at this point it’s JavaScript itself

MichaelSt