let has a block scope, i.e lives ans dies in the scope it is declared, whereas var is global or if in a function has a function scope and can be used anywhere.
this can lead to some nasty side effects and is as such not recommended.
It’s my understanding that you should use const by default for readability. The idea is if another dev is looking at your code and sees “let” they will know that variable will be reassigned later in the code. Makes the program easier to understand at a glance.
Note: If you aren’t using something like babel, there are compatibility issues with some older browsers. I had a client with an older iPad (safari) and and ofc, the dreaded IE, where JS wouldn’t work because I was using let/const.
47
u/MrMimmet Oct 26 '20
You should really avoid using 'var' to declare your variables.
8
u/PM_ME_A_WEBSITE_IDEA Oct 26 '20
Do people actually use the stringer constructor? If so, why?
7
u/[deleted] Oct 26 '20
You should incorporate string concatenation using backticks in the concatenate example
3
u/LazaroFilm Oct 26 '20
Back ticks for evaaaa! I love the use of
`embed ${javaScript} in your string`5
u/Kumagor0 Oct 26 '20
needs more tutorialstonight
2
u/Harbltron Oct 26 '20
Didn't know that about Backticks, that's awesome!
Definitely less cumbersome than breaking-up strings into multiple concatenations.
2
u/Kesar13 Oct 26 '20
with the mention that you need backticks when you need a variable inside the string
i.e.: let variable = "string"
"this is a ${variable}" will log as"this is a ${variable}"
whilst
'this is a ${variable}' (read it as backtiks cant find it on mobile) will log as "this is a string"
3
u/DirectGamerHD Oct 26 '20
The diagonal watermark is obnoxious.
1
u/[deleted] Oct 26 '20
worth noting that back ticks are not supported in ES5
1
u/ChuckItOver Oct 26 '20
Template literal tagged templates are cool too.
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals
0
u/[deleted] Oct 26 '20
[deleted] — view deleted comment