As a developer who strongly prefers the functional paradigm, it's save to say that my opinions often times differ with Chris', but I always enjoy watching him and gaining insight on what other developers may lay value on. I also appreciate how he seperates facts from opinions and lays them out very clearly.
Just wanna say how great of an explainer Chris Ferdinandi is. I purchased some of his courses and they were the only ones that really clicked for me in understanding JavaScript. Even sometimes when I hit a barrier of knowledge, Chris's site is my first go-to to check if he has a Blogpost or course about it.
After working with languages like C and C++, I started thinking of variables as pointers of memory storage, rather than value storage. With that mindset, const is a constant reference to a memory pointer that can't be reassigned, but object properties/qualities stored in the pointer can be altered. This explains why arrays and objects (and scalar prototypes) can be changed, but scalar values cannot. I also subscribe to const primarily, but I'm generally biased towards OOP, where most variables I work with are objects anyway, so I make very limited use of let. An example of such limited use is with traditional for and while loops, though for arrays of objects, using const (for const x of y {...}) is just fine.
I, personally, prefer const over let and only use let if I need the variable to change within a single iteration of the function. I tend to set up const with a ternary if I need it conditional different for that single iteration but will always be that value for that iteration.
Never let your ternaries get out of hand. If it is more than one ? & a : then it most likely to complex to read in another month. I agree with you for the most part though.
@@deatho0ne587 Yup. Usually a rare case a const can have more than 2 options, though. And if it does, it usually means you need more variables to break down everything that is going on.
Another really fun one dude! I do interviewing for my job and if I was to offer some unsolicited advice; a few more affirmation noises from you would really help ease the tension in these guest videos. Whenever you nod and smile, pairing it more frequently with a sound like "ahh", "uhuh", "got it!" goes a long way to keep you present in the dialogue and confirm to the guest subconsciously that this is still a conversation. They're a guest after all, so we're watching two people not one. Additionally, looking directly into the lens is lovely when you're just addressing us, but you'll notice that none of your guests do that. They're always looking at you, but slightly off to the side. This is just standard learned body language for video calls, so if your guest is doing it, you should probably mirror it. And I really love when you interject to clarify things it's really helpful.
I'm glad Kevin doesn't repeatedly vocalise acknowledgement on points, I feel like once I start noticing that it will become too distracting and I'll keep thinking to myself "Dude shut up and just let him talk." Although it's a guest video, I don't think it's meant to have an interview theme. I'm personally more focused on the delivery of raw information than the video presentation surrounding the content delivery. I've been a interviewee a number of times in programming roles with non-technical interviewers and feel like I get discriminated against because I'm not that social, I'm a quiet person, I'm not an open book, I'm very privacy-focused, I'm conservative and keep personal traits to myself, but I do know how to program and am very confident with it, but tend to have difficulties with interviews so I don't think making a video like this interview-focused is relatable or a good idea at all.
Although they exist, there are very few situations where you would NOT want variable scoping - I changed var to let in all of my legacy code, and I think I can count on one hand the number of times it needed to remain var.
Thanks, Kevin! This has been an open tab since it came out. Finally watched it. Chris is so very good at these kinds of explanations. This one was very helpful.
To be honest, I'm still experimenting with variables like const, var, and let, regardless of the number of courses I've taken and videos I've watched. It seems to me it's somewhat of a trend; I use const or var based on my current mood.
One more thing about var compared to const and let is that var DECLARATIONS get hoisted during runtime. The ASSIGNMENT of the variable happens in line though, so if the code declares and assigns a variable at the bottom of the script but is used at the top of the script, the engine will determine that variable as undefined at that point (rather than giving a refereceError if you used const or let). It's similar to how traditional function declarations get hoisted, except with functions the assignment of the function also gets hoisted with the declaration
A small thing that also differs with these, is when a variable is declared in the global scope. If you are using var globally, that variable will attach to the window object, meaning you can access it by window.myVariable. let and const doesn't do this. That means, that should you be in the quite specific scenario of having to access the global variable by string, like this window["myVariable"], it can only be done with var. It is a quite narrow scenario, but I have come across the need of it myself.
and also if you don't use var/let/const to declare it (though then if you're using strict mode it will throw error). It will be like writing window.myVariable
I always use 'const' by default. I've found over the years that if I feel compelled to use 'let' it's usually an indicator that my code might not be as robust as it could be. I'll never understand the "let" is two letters shorter argument. Any "savings" you gain from typing two fewer characters is swallowed up by host of other work that you need to do as a developer. No one is counting your keystrokes (at least, I hope not).
Lots of situations where a variable is changing value, e.g. the index number of the current slideshow image, strings like page-state , booleans like a cycling indicator on an animatable/off part of a web page. There will be a *let* - it must be 🎹
@@dankierson Take a look at declarative and functional programming paradigms. JS isn't a fully functional lang, but it's close enough that you can refactor a lot of imperative code in ways that greatly reduce the use of 'let'.
@@ripwolfe And we all do, Wolfe. But we can't remove it entirely. Besides, where's the harm in *let* ? It's not *var* we're talking about here. Storm in a cawfee cup for Chrissakes.
i also go the always const route. But another way someone could do it, is just use their let and then let the linter decide at the end :D If the variable is not changed, let it replace your lets with const.... would also be a solution. But id rather do default const.
I agree with the comments and disagree with the host. const unless need to be let. and 'var' is just bad No thumbs up. A first time for when I watch videos on this channel.
My approach: Is it a object? Yes - const No - Can it change at runtime? Yes - let No - const The only place I use var for are closures which are like objects with private properties. Also I don't 100% stick to this approach. I sometimes use var for the things declared in the few first lines globally and sometimes I change a variable into a object in those lines without making it a const, which I should not do.
8:40 especially with ts, or jsdoc comments, its better to use const, because `let`s says value can change and typescript acts like it can change too, making your life harder.
I think const vs let should reflect the intent of the code, do you want it to change or not? Plus if one of my developers tried to commit code that relied on the fuzzy nature of var to work I would tell them to rewrite it so it didn't
A big thing not mentioned is that var can be hoisted from anywhere in the code , which can cause issues , that’s why let is there . Const does not make sense in JavaScript, because it is not really a constant as it would be in other languages . I think of const as a good motivator / indicator to be mindful of where and when you declare a variable.
I'd say the constant part of const is a reference to the pointer of the variable than to the contents of the variable. Ie. If const x = { name: "bob" }, then the pointer reference of that object is stored to x, and a pointer to a separate object (say { name: "sally" }) cannot be set to x. However, you can update x.name = "sally", because the pointer of the variable is not changing. { name: "sally" } !== { name: "sally" }
I have never had any training so I found 'var' easy to remember and use it everywhere and rarely had any problems and when I do, I use const. But it's good to have a proper explanation!
To me, const is the default not because it is special, but because let is. I use let to let others know that the value is going to change down the line.
I'm a "lazy developer" too, but that means setting up tools and automations to do boring / repetitive tasks so then I never have to waste time thinking about it. My IDE, ESLint, and Prettier take care of automatically catching and updating let and const declarations. Also, you absolutely should worry about variables changing, that's part of building software. And if you don't want to think about it, then defaulting to const makes more sense; if the variable shouldn't be re-assigned, you're good. If the variable should be re-assigned, then your IDE/linting/build-tooling will let you know and you can update it.
I use const when I'm defining html elements with querySelector. What I think development comes down to is: programming is a language, and everyone has an accent. Your accent might be a refined English accent (think Patrick Stewart), while someone else might "sound" like Hank Hill. Personally, my accent would be similar to the cross-eyed guy from "The Waterboy."
One more important aspect regarding var ,let &const is var can approach to global scope results in memory consumption while deallocating after execution
It would cool to mention that you can achieve array or object immutability using `Object.freeze`. This is especially handy for enums. Just note that freezing is not deep, i.e. it doesn’t protect nested objects.
As per your first example, without var, variables are puts into the global space. Clearly different than using var. var is function scoped. Your example just happens to be in a global space.
Nice intro. Opinionated. But hey...aren't we all ;-) Just a few things: You _should_ but do not need to declare a variable. That is how 'global' jQuery ($) and Underscore (_) work. In general this is a good approach for global utility libraries. Scoping has its uses but so do global variables or functions. You can not re-assign a new value to a const. But if it is an object you still can add key-value pairs or modify the value of any key. If you do not want that (say for lookup tables with constants) you can 'freeze' the const. So: nice helpful intro...thanks for sharing. But IMHO it is slightly more complicated - apart from programming style ;-)
Thank you! One of the things about being full stack (hardware-db-middleware-backend-frontend) is you embody "Jack of all trades, master of none." I often wondered why the three declaration types but never took the time to explore. Funny that I find out after I retire.
@@SW-fh7he When I started working with JS, Let was not part of it, in fact I have not used much JS since Let became part of it, since JS is not part of my normal stack these days ... so I can see why someone that is retired now may not have considered it much.
Leave JavaScript to others, Kevin, if this is your goto guy. It's nuts to use *let* unless its flexibility is needed: never give a system more entropy than it needs. Makes far more sense to use *const* for all Object types in JS, this includes collections of any type, primitive or Object. And for primitive types ask yourself if this thing is ever going to change . . . if so, use *let* and otherwise use old *const* again. To hell with *var*
The missing info is that "var" was the only variable type for a long time and now it is practically left in JS only for compatibility with the older code. Not for use in new codes.
Only thing that var is useful for are closures and they can be mimicked with a objest created from a class that has private properties. So most of the time you don't need it
In that example with wixard and item... Let also shouldnt work becauae item is already defined?? You cant access the inner one once it ends but inside the inner one you can definitely access the outer one...
I guess muscle memory and not planning out what certainly won't change at runtime and what can, which is bad cause you as a programmer should have at least a rough idea of it
It's mind boggling to me how so many people, _especially_ tutors, present const as being "strange" or "incomplete" because it does not change the inner behavior of a class, object or function (in particular mutability of inner state). It would be _weird_ if it did. The only explanation I have for this is that such folk have never understood values vs. references in the first place, and consequently have no idea of basic OOP concepts. Or they _do_ understand the difference between values and references, but whine about _having to_, or to have to teach it. Imagine there was no way to do the opposite, if you'd have to use "let" or "mutable" to be able to manipulate an array once you assigned it. Imagine a buffer would either be externally mutable _and_ reassignable or unmutable and non-reassignable. LOL. But that is what folks that find the meaning of const "strange" or "incomplete" imply would be "more correct" or "complete". So please! Just stop even suggesting to beginners that the const behaviour is -- in any way -- strange or incomplete or weird or odd. In fact teach them how and why it is _not_!
I'm all for being a lazy developer, but using 'let' instead of 'const' because it's easier to type is a wild take. Probably the canary in the coalmine of generally not great code.
the issue is every teachers don't tell you the same thing; they say don't use Var cos it's for Java! then you see videos on utube with people using Var everywhere...then others will use const everywhere..so once again this is confusing and seeing Kevin noding like he understood everything makes me wonder, what will he use if he writes javascript?!
The problem with 'let' as the default is that I as the user, can now also change the value. Which means if you have forgotten to validate everything on the backend before it goes into the database, the user wins. I am in the 'const as default' camp. Also, don't think of it as 'changing the variable' think of it as 'overriding the existing value of the variable with a new value'. Let lets you override or replace the existing value with a new one, const does not. Once you think like that, it becomes obvious why arrays work with const. Also note that Javascript isn't the only one that lets you manipulate a const array, other languages allow it too, so Javascript in this instance is just following the norm. One of the few languages that won't let you define an array as a const is 'C#', you have to define it as readonly there.
Lots of talk and not a word about performance. When 'var' is converted to bytecode, the scope check procedure call is skipped, so it's faster than 'let' or 'const'.
6 месяцев назад+1
"Worry about the performance of your code when and if your code has a performance problem." The difference is neglibile in the vast majority of cases.
As someone who dabbles in web dev, I find this video to be lazy content. Sure, the title basically attracts beginner developers but there's nothing here in 12 min that isn't in a 60 second Fireship video. There's not a lot of value in the explanation or examples either. The basic yet incredibly key piece of information that the guy does not state explicitly is that `const` does not allow *"reassignments"* which is a really important concept in computer science and more specifically memory management and leads nicely into an explanation on why `const` was introduced when `let` had already existed, why it's actually not strange pushing to a const declared list and why one might want to use `const` instead of `let`.
const should always be used unless absolutely necessary to use let. It's much safer that way. If a developer who works for me told me he uses "let" instead of "const" because of the excuses you've just given, I'd fire him immediately. Your guest is not the sharpest, Kevin, and a terrible choice to invite. You should not have published this video.
const until you can't
Well said buddy.
Fully agree
Yup, and just about any linting config will say the same.
Yup, and then use let :)
As a developer who strongly prefers the functional paradigm, it's save to say that my opinions often times differ with Chris', but I always enjoy watching him and gaining insight on what other developers may lay value on. I also appreciate how he seperates facts from opinions and lays them out very clearly.
Just wanna say how great of an explainer Chris Ferdinandi is. I purchased some of his courses and they were the only ones that really clicked for me in understanding JavaScript. Even sometimes when I hit a barrier of knowledge, Chris's site is my first go-to to check if he has a Blogpost or course about it.
After working with languages like C and C++, I started thinking of variables as pointers of memory storage, rather than value storage.
With that mindset, const is a constant reference to a memory pointer that can't be reassigned, but object properties/qualities stored in the pointer can be altered. This explains why arrays and objects (and scalar prototypes) can be changed, but scalar values cannot.
I also subscribe to const primarily, but I'm generally biased towards OOP, where most variables I work with are objects anyway, so I make very limited use of let. An example of such limited use is with traditional for and while loops, though for arrays of objects, using const (for const x of y {...}) is just fine.
I use const for constants and var for variables :D
By the way, I fully support JS content on this channel. (Pure JS, not that crap from frameworks).
I, personally, prefer const over let and only use let if I need the variable to change within a single iteration of the function. I tend to set up const with a ternary if I need it conditional different for that single iteration but will always be that value for that iteration.
Never let your ternaries get out of hand. If it is more than one ? & a : then it most likely to complex to read in another month.
I agree with you for the most part though.
@@deatho0ne587 Yup. Usually a rare case a const can have more than 2 options, though. And if it does, it usually means you need more variables to break down everything that is going on.
I agree with you. Just do not want people doing something that can be hard to maintain.
Another really fun one dude!
I do interviewing for my job and if I was to offer some unsolicited advice; a few more affirmation noises from you would really help ease the tension in these guest videos. Whenever you nod and smile, pairing it more frequently with a sound like "ahh", "uhuh", "got it!" goes a long way to keep you present in the dialogue and confirm to the guest subconsciously that this is still a conversation. They're a guest after all, so we're watching two people not one.
Additionally, looking directly into the lens is lovely when you're just addressing us, but you'll notice that none of your guests do that. They're always looking at you, but slightly off to the side. This is just standard learned body language for video calls, so if your guest is doing it, you should probably mirror it.
And I really love when you interject to clarify things it's really helpful.
I'm glad Kevin doesn't repeatedly vocalise acknowledgement on points, I feel like once I start noticing that it will become too distracting and I'll keep thinking to myself "Dude shut up and just let him talk." Although it's a guest video, I don't think it's meant to have an interview theme. I'm personally more focused on the delivery of raw information than the video presentation surrounding the content delivery. I've been a interviewee a number of times in programming roles with non-technical interviewers and feel like I get discriminated against because I'm not that social, I'm a quiet person, I'm not an open book, I'm very privacy-focused, I'm conservative and keep personal traits to myself, but I do know how to program and am very confident with it, but tend to have difficulties with interviews so I don't think making a video like this interview-focused is relatable or a good idea at all.
He's constantly noding it's annoying. If he added even more sounds too; I would be driven insane.
Although they exist, there are very few situations where you would NOT want variable scoping - I changed var to let in all of my legacy code, and I think I can count on one hand the number of times it needed to remain var.
Thanks, Kevin! This has been an open tab since it came out. Finally watched it. Chris is so very good at these kinds of explanations. This one was very helpful.
Const should always be the default.
To be honest, I'm still experimenting with variables like const, var, and let, regardless of the number of courses I've taken and videos I've watched. It seems to me it's somewhat of a trend; I use const or var based on my current mood.
One more thing about var compared to const and let is that var DECLARATIONS get hoisted during runtime. The ASSIGNMENT of the variable happens in line though, so if the code declares and assigns a variable at the bottom of the script but is used at the top of the script, the engine will determine that variable as undefined at that point (rather than giving a refereceError if you used const or let). It's similar to how traditional function declarations get hoisted, except with functions the assignment of the function also gets hoisted with the declaration
A small thing that also differs with these, is when a variable is declared in the global scope. If you are using var globally, that variable will attach to the window object, meaning you can access it by window.myVariable. let and const doesn't do this. That means, that should you be in the quite specific scenario of having to access the global variable by string, like this window["myVariable"], it can only be done with var. It is a quite narrow scenario, but I have come across the need of it myself.
and also if you don't use var/let/const to declare it (though then if you're using strict mode it will throw error). It will be like writing window.myVariable
I always use 'const' by default. I've found over the years that if I feel compelled to use 'let' it's usually an indicator that my code might not be as robust as it could be. I'll never understand the "let" is two letters shorter argument. Any "savings" you gain from typing two fewer characters is swallowed up by host of other work that you need to do as a developer. No one is counting your keystrokes (at least, I hope not).
Elon probably is 😂
Lots of situations where a variable is changing value, e.g. the index number of the current slideshow image, strings like page-state , booleans like a cycling indicator on an animatable/off part of a web page.
There will be a *let* - it must be 🎹
@@dankierson Take a look at declarative and functional programming paradigms. JS isn't a fully functional lang, but it's close enough that you can refactor a lot of imperative code in ways that greatly reduce the use of 'let'.
@@ripwolfe And we all do, Wolfe. But we can't remove it entirely. Besides, where's the harm in *let* ? It's not *var* we're talking about here. Storm in a cawfee cup for Chrissakes.
i also go the always const route. But another way someone could do it, is just use their let and then let the linter decide at the end :D
If the variable is not changed, let it replace your lets with const.... would also be a solution. But id rather do default const.
I agree with the comments and disagree with the host.
const unless need to be let.
and 'var' is just bad
No thumbs up. A first time for when I watch videos on this channel.
He's not the host. He's the guest. But you should know that since you have watched the channel before.
My approach:
Is it a object?
Yes - const
No - Can it change at runtime?
Yes - let
No - const
The only place I use var for are closures which are like objects with private properties.
Also I don't 100% stick to this approach. I sometimes use var for the things declared in the few first lines globally and sometimes I change a variable into a object in those lines without making it a const, which I should not do.
8:40 especially with ts, or jsdoc comments, its better to use const, because `let`s says value can change and typescript acts like it can change too, making your life harder.
Glad you two got together finally!
I think const vs let should reflect the intent of the code, do you want it to change or not? Plus if one of my developers tried to commit code that relied on the fuzzy nature of var to work I would tell them to rewrite it so it didn't
My thoughts exactly...
A big thing not mentioned is that var can be hoisted from anywhere in the code , which can cause issues , that’s why let is there . Const does not make sense in JavaScript, because it is not really a constant as it would be in other languages . I think of const as a good motivator / indicator to be mindful of where and when you declare a variable.
I'd say the constant part of const is a reference to the pointer of the variable than to the contents of the variable. Ie. If const x = { name: "bob" }, then the pointer reference of that object is stored to x, and a pointer to a separate object (say { name: "sally" }) cannot be set to x.
However, you can update x.name = "sally", because the pointer of the variable is not changing.
{ name: "sally" } !== { name: "sally" }
I have never had any training so I found 'var' easy to remember and use it everywhere and rarely had any problems and when I do, I use const. But it's good to have a proper explanation!
To me, const is the default not because it is special, but because let is. I use let to let others know that the value is going to change down the line.
I'm a "lazy developer" too, but that means setting up tools and automations to do boring / repetitive tasks so then I never have to waste time thinking about it. My IDE, ESLint, and Prettier take care of automatically catching and updating let and const declarations.
Also, you absolutely should worry about variables changing, that's part of building software. And if you don't want to think about it, then defaulting to const makes more sense; if the variable shouldn't be re-assigned, you're good. If the variable should be re-assigned, then your IDE/linting/build-tooling will let you know and you can update it.
I use const when I'm defining html elements with querySelector.
What I think development comes down to is: programming is a language, and everyone has an accent. Your accent might be a refined English accent (think Patrick Stewart), while someone else might "sound" like Hank Hill. Personally, my accent would be similar to the cross-eyed guy from "The Waterboy."
I like that analogy! Though no need to be so hard on yourself 😂
I am happy u teach us JavaScript now
One more important aspect regarding var ,let &const is var can approach to global scope results in memory consumption while deallocating after execution
It would cool to mention that you can achieve array or object immutability using `Object.freeze`. This is especially handy for enums. Just note that freezing is not deep, i.e. it doesn’t protect nested objects.
You can prevent that with good (1d) data structuring ;-)
As per your first example, without var, variables are puts into the global space. Clearly different than using var. var is function scoped.
Your example just happens to be in a global space.
can you do a tutorial about NPM? i've been searching a npm tutorial but almost are 5yrs ago, and i cant follow it cause its not updated.
Nice intro. Opinionated. But hey...aren't we all ;-)
Just a few things:
You _should_ but do not need to declare a variable. That is how 'global' jQuery ($) and Underscore (_) work. In general this is a good approach for global utility libraries.
Scoping has its uses but so do global variables or functions.
You can not re-assign a new value to a const. But if it is an object you still can add key-value pairs or modify the value of any key.
If you do not want that (say for lookup tables with constants) you can 'freeze' the const.
So: nice helpful intro...thanks for sharing. But IMHO it is slightly more complicated - apart from programming style ;-)
bundlers and transpilers still convert `let` and `const` into `var` and also move the declarations if necessary.
Example? I never noticed this...
Typescript - const arr = [...] as const; none mutable array.
Seeing var in my old company code gives me anger
Love these shorter gap closing videos! Keep up the great work, Kevin!
If you're looking for short videos with good examples that deliver a good amount of information, might I recommend Fireship's videos and shorts.
Thank you! One of the things about being full stack (hardware-db-middleware-backend-frontend) is you embody "Jack of all trades, master of none." I often wondered why the three declaration types but never took the time to explore. Funny that I find out after I retire.
@@SW-fh7he When I started working with JS, Let was not part of it, in fact I have not used much JS since Let became part of it, since JS is not part of my normal stack these days ... so I can see why someone that is retired now may not have considered it much.
And the best part is - Programm works even without let, var, or const... 😊
variable= value;
Kevin with JS ❤
Thanks Kevin for the video
Kevin we want you teach us JavaScript also . Thank you kavin
Thank you both.
I was hoping this video would start with “hello my backend friends” 😂
it's still frontend though
Be careful what you wish for. Kevin will be trying to teach us PHP next.
And you can declare a var in a function and change its value in another function, right? (which you can"t do with let)
Great video. Thank you!
I thought we would talk about hoisting here :(
Leave JavaScript to others, Kevin, if this is your goto guy.
It's nuts to use *let* unless its flexibility is needed: never give a system more entropy than it needs.
Makes far more sense to use *const* for all Object types in JS, this includes collections of any type, primitive or Object.
And for primitive types ask yourself if this thing is ever going to change . . . if so, use *let* and otherwise use old *const* again.
To hell with *var*
I ❤const
The missing info is that "var" was the only variable type for a long time and now it is practically left in JS only for compatibility with the older code. Not for use in new codes.
Good point...Var comes from the days of Windows XP...
@@montebont "var" comes long before WinXP.
G: "JS type "var" since when"
I use IntelliJ for all my coding, and it always likes to replace var with let or const. Is there anytime where var would still be useful?
Generally, no. The actual use cases are so niche, I wouldn't even worry about them
Only thing that var is useful for are closures and they can be mimicked with a objest created from a class that has private properties. So most of the time you don't need it
@@kacperkonieczny7333 Please elaborate as I use closures a lot and never saw any need or advantage for a *var* there.
In that example with wixard and item... Let also shouldnt work becauae item is already defined?? You cant access the inner one once it ends but inside the inner one you can definitely access the outer one...
I'm not entirely sure why it is hard to use "const" most of the time and use "let" when you need it. I just don't get it.
I guess muscle memory and not planning out what certainly won't change at runtime and what can, which is bad cause you as a programmer should have at least a rough idea of it
RSI, those two extra letters will destroy your wrists.
Javascript finally!
Thanks!
And again!
I’m using const since some time now. Even for defining functions. To me it makes the behavior much more predictable!
i'm old and grumpy and still use var for everything.
thanks nerds :)
It's mind boggling to me how so many people, _especially_ tutors, present const as being "strange" or "incomplete" because it does not change the inner behavior of a class, object or function (in particular mutability of inner state). It would be _weird_ if it did. The only explanation I have for this is that such folk have never understood values vs. references in the first place, and consequently have no idea of basic OOP concepts. Or they _do_ understand the difference between values and references, but whine about _having to_, or to have to teach it.
Imagine there was no way to do the opposite, if you'd have to use "let" or "mutable" to be able to manipulate an array once you assigned it. Imagine a buffer would either be externally mutable _and_ reassignable or unmutable and non-reassignable. LOL. But that is what folks that find the meaning of const "strange" or "incomplete" imply would be "more correct" or "complete".
So please! Just stop even suggesting to beginners that the const behaviour is -- in any way -- strange or incomplete or weird or odd. In fact teach them how and why it is _not_!
I'm all for being a lazy developer, but using 'let' instead of 'const' because it's easier to type is a wild take. Probably the canary in the coalmine of generally not great code.
the issue is every teachers don't tell you the same thing; they say don't use Var cos it's for Java! then you see videos on utube with people using Var everywhere...then others will use const everywhere..so once again this is confusing and seeing Kevin noding like he understood everything makes me wonder, what will he use if he writes javascript?!
thanks for this. I've wondered this for a long time.
last thing i expeceted to see on this channel lol
The problem with 'let' as the default is that I as the user, can now also change the value. Which means if you have forgotten to validate everything on the backend before it goes into the database, the user wins.
I am in the 'const as default' camp.
Also, don't think of it as 'changing the variable' think of it as 'overriding the existing value of the variable with a new value'.
Let lets you override or replace the existing value with a new one, const does not. Once you think like that, it becomes obvious why arrays work with const.
Also note that Javascript isn't the only one that lets you manipulate a const array, other languages allow it too, so Javascript in this instance is just following the norm.
One of the few languages that won't let you define an array as a const is 'C#', you have to define it as readonly there.
The biggest crime here is not 'var' but using light mode in his editor 😮
is item a variable within the var variable... lost...
Love this
Well we need two more; int and float
A constant isn't a variable
You should bother to think about whether your variable will change.
var reading this comment section be like: "Time to go rogue" 🤨🤨
12 minutes?
Tl;dw
Don't use var
If it can change use let
If it can't change use const
Lots of talk and not a word about performance. When 'var' is converted to bytecode, the scope check procedure call is skipped, so it's faster than 'let' or 'const'.
"Worry about the performance of your code when and if your code has a performance problem."
The difference is neglibile in the vast majority of cases.
It also helps memory management...
As someone who dabbles in web dev, I find this video to be lazy content. Sure, the title basically attracts beginner developers but there's nothing here in 12 min that isn't in a 60 second Fireship video. There's not a lot of value in the explanation or examples either. The basic yet incredibly key piece of information that the guy does not state explicitly is that `const` does not allow *"reassignments"* which is a really important concept in computer science and more specifically memory management and leads nicely into an explanation on why `const` was introduced when `let` had already existed, why it's actually not strange pushing to a const declared list and why one might want to use `const` instead of `let`.
const should always be used unless absolutely necessary to use let.
It's much safer that way. If a developer who works for me told me he uses "let" instead of "const" because of the excuses you've just given, I'd fire him immediately.
Your guest is not the sharpest, Kevin, and a terrible choice to invite. You should not have published this video.
There are betters channels to learn and understand Javascript (same for css).
use var wizard, not var item stupid mistake
Make a video on responsive design
I unsub'ed from Chris' newsletter after a few emails where he started talking politics. Keep that toxic sh*t out bro.
let as the deafult ? Smh
Someone call the FBI
real men only use var
real men only use binary ...