Тёмный

16.2: const - Topics of JavaScript/ES6 

The Coding Train
Подписаться 1,7 млн
Просмотров 75 тыс.
50% 1

In this video, I cover the JavaScript ES6 keyword "const." This is a continuation of the previous video about "let" and "var."
Video on "let": • 16.1: let vs var - Top...
Support this channel on Patreon: / codingtrain
To buy Coding Train merchandise: www.designbyhumans.com/shop/c...
To Support the Processing Foundation: processingfoundation.org/support
Send me your questions and coding challenges!: github.com/CodingTrain/Rainbo...
Contact:
Twitter: / shiffman
The Coding Train website: thecodingtrain.com/
Source Code for the all Video Lessons: github.com/CodingTrain/Rainbo...
p5.js: p5js.org/
Processing: processing.org
For an Intro to Programming using p5.js: • Start learning here!
For Coding Challenges: • Coding Challenges
Help us caption & translate this video!
amara.org/v/dXl1/
📄 Code of Conduct: github.com/CodingTrain/Code-o...

Опубликовано:

 

8 июл 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 125   
@isaiahharris6800
@isaiahharris6800 4 года назад
Watched you when I wrote my first line of code and still watching 4 years later as a professional
@kashtonsebastian4802
@kashtonsebastian4802 2 года назад
i know Im asking the wrong place but does anyone know of a trick to log back into an instagram account?? I was stupid forgot the password. I love any tricks you can offer me!
@anakinjulio2003
@anakinjulio2003 2 года назад
@Kashton Sebastian instablaster =)
@kashtonsebastian4802
@kashtonsebastian4802 2 года назад
@Anakin Julio Thanks so much for your reply. I found the site thru google and Im trying it out now. I see it takes a while so I will get back to you later when my account password hopefully is recovered.
@amrmohamed2608
@amrmohamed2608 6 лет назад
you are without question one of the best tutors on RU-vid, i really enjoy watching your videos and the way you teach is very interesting.
@ark333
@ark333 4 года назад
yes and he's pretty funny too, I love his videos
@MJ-ih1yu
@MJ-ih1yu 3 года назад
Definitely ,,,,,, 👌a best teacher
@amirmehrizi6045
@amirmehrizi6045 2 года назад
OMG - Finding you and your channel is like finding unlimited access to the treasury. GOD bless you man
@TheCodingTrain
@TheCodingTrain 2 года назад
Welcome aboard!
@benjhabert
@benjhabert 6 лет назад
for me const is useful for clarity when I am working on a collaborative project. If someone uses const it explicitly says "don't mess with this variable"
@TheCodingTrain
@TheCodingTrain 6 лет назад
Great point!
@farhanaditya2647
@farhanaditya2647 3 года назад
Never thought about that, thanks!
@krawieck
@krawieck 6 лет назад
Const is very useful in node.js for including libraries. Eg.: const fs = require ('fs') // filesystem module
@TheCodingTrain
@TheCodingTrain 6 лет назад
Thanks, great point!
@calonyoutube
@calonyoutube 6 лет назад
also in react.js to declare components
@ahlambeyoud1709
@ahlambeyoud1709 6 лет назад
the amount of energy in your videos makes coding so fun, I am a beginner and just wanna tell you that you make things very clear and simple thank you very much !
@alekmoth
@alekmoth 6 лет назад
Most people that argue that you should use const whenever you can are not going to even mention the single argument you did, the premature optimization. The reasons to use immutable references are mostly for the writer and reader of the code. To avoid bugs and be clearer about the intention of that reference when it was defined. It stops "other people" (like you fifteen minutes later) from reusing the "variable" later in the code and this duplication causes unknown side effects with the original intended code.
@TheCodingTrain
@TheCodingTrain 6 лет назад
Thanks for this clarification. I am considering redoing this video as I overemphasized non-existent optimization benefits and de-emphasized the code maintenance benefits! Thank you for commenting!
@purpleice2343
@purpleice2343 6 лет назад
While premature optimization is worst thing possible you could do, doesn't mean you should completely stop thinking about it (just like what pretty much 99% of people do once they hear that it's "evil"). If you know that variable will never change, make it constant, it doesn't change readability in any way and it's free optimization which doesn't slow down your progress by any means... There's no reason to "oh I'll change all 300 variables, if I need a little bit more performance, that never change later, that's fun thing to do, right?", how about just do it right now.
@AliBaba-hn8tv
@AliBaba-hn8tv 3 года назад
Learn with lots of fun, the best teacher ever.
@gkarapeev
@gkarapeev 5 лет назад
Dude, you are awesome at explaining things. No matter how simple or difficult they are. I watched a video of you talking about fractals and imaginary numbers and it was just as clear as this one. Thanks for the quality content!
@victorirekponor6858
@victorirekponor6858 4 года назад
I love this guy! I am making a switch from Python to Js and with your tutorials everything just feels so seamless and super easy!!! Great videos.
@evhwolfgang2003
@evhwolfgang2003 6 лет назад
Last time I did any programming, HTML5 was brand new and jQuery did all of my front end stuff (I was more concerned with PHP at the time). Your channel is awesome for catching up and filling in those "self taught" gaps. Subscribed when you dropped your marker in the Var vs Let video. Love your style man!
@yuyafujikawa1729
@yuyafujikawa1729 6 лет назад
6:43 to 6:54 the summary of this video. Thank you!! I now understand this! You explain things so good!!
@watchdogman9956
@watchdogman9956 4 года назад
Super Helpful! Watching this right now as I am trying to become a programmer to support my family! Thanks, friend!
@bearded-cat
@bearded-cat 6 лет назад
I can't get enough of your videos!
@voltihd4287
@voltihd4287 2 года назад
Great teacher, your videos are a go-to for my school work since there is not enough clarity with assignment instructions. Thank you!
@ky-effect2717
@ky-effect2717 3 года назад
Thanks for the detailed descriptions!
@Sworn973
@Sworn973 6 лет назад
No more neural network :'(, I was following with my project, crazy to see how you explain and use it. You explain waaaayyyyyyy better then every one else.
@kubimogero
@kubimogero 6 лет назад
Looking forward watching arrow syntax!
@rachanaa6745
@rachanaa6745 2 года назад
thank you for detailed explanation !!
@HamdiRizal
@HamdiRizal 6 лет назад
Your videos are really fun to watch. Please make more video about learning javascript. :)
@persenbp4160
@persenbp4160 3 года назад
incredible ! thank you !
@syeddanialnabi9813
@syeddanialnabi9813 6 лет назад
Const is simply Great :)
@TheNewGreenIsBlue
@TheNewGreenIsBlue 2 года назад
The underlying reason *const* allows you to change the values is because when you create an object, the *ACTUAL* thing that is being stored as the value is the memory address which POINTS to the data. It's like storing *123 Main Street* as the value... and saying you can NOT change that. It is forever 123 Main st.... although you can alter what's inside the house. When you use let, you're still assigning a memory address (when creating an object), but it's more like you're saying... hey this is a mobile home, so I need to be able to destroy, move or point it at a different mobile home. Using const prevents you from doing something like this: `const china = { democracy: false }; const taiwan = { democracy: true }; china = taiwan;`
@BloodyScythe666
@BloodyScythe666 6 лет назад
thank you for the video and its useful information. I'd be glad if you also explain "=>"
@arielmarvin8890
@arielmarvin8890 3 года назад
i really apreciated your video i understand the idea of a function , maybe some exercises more and i can love the javascript more than now , new follower
@WistrelChianti
@WistrelChianti Год назад
very clear thanks!!
@TheLargedwarf
@TheLargedwarf 6 лет назад
One of the strengths of cost is that you might find yourself with a loop containing a "let" for a variable that doesn't change this is slower than it needs to be because let goes and finds some memory, and then sets it to the required value. Const stops the need to find or set the memory more than once, essentially it's a line of code that will only run on the first cycle of the loop. To preserve this use it's important you can't break it by reassigning the value somewhere.
@zinsy23
@zinsy23 4 года назад
I thought I pretty much knew what there was to const. Now I watch a 7 minute video where I learn a bunch of stuff I never knew!
@mehtisup
@mehtisup Год назад
Thank you.
@nurharizulaimanmatharith4023
@nurharizulaimanmatharith4023 4 года назад
Great videos
@KDC_365
@KDC_365 3 года назад
I love you, boss. From Bangladesh
@dwhxyz
@dwhxyz 6 лет назад
If your starting to discuss ES6 then it might be helpful to do a couple of videos on TypeScript. Btw, love your videos :D
@GSquaredOG
@GSquaredOG 6 лет назад
You could also make a video about parameter defaults. Those are kinda cool.
@drivgest
@drivgest 6 лет назад
great explanation.... var, let, const........ 👍🏻
@DiegoMQuinteros
@DiegoMQuinteros 6 лет назад
Thanks sir!
@emmanuelvillegas4403
@emmanuelvillegas4403 6 лет назад
Thanks!!
@faisaltaher851
@faisaltaher851 6 лет назад
thx
@EMonzon
@EMonzon 6 лет назад
very funny guy! very good for learning difficult things.
@mikakataja5783
@mikakataja5783 6 лет назад
Feature request for ES7: modifier word "it" for let, where you can insert "this" into the newly created variable scope, thus we could make by then very dated "let it go() {}" jokes.
@0791679
@0791679 6 лет назад
I've been using ES2016 (Not ES6 anymore) for couple of years now. And I use const more then let. For node development I rarely use let. So my default behaviour is to use const and if needed I use let. Watching this video with a Junior developer...
@TheCodingTrain
@TheCodingTrain 6 лет назад
Thanks, I am very behind the times!
@newbprogramming5043
@newbprogramming5043 6 лет назад
6:57 anonymous functions are awesome // Instead of function gotData(data) { } loadJSON(url, gotData); // You can do this: loadJSON(url, function(data) { }); // Or even this: ('arrow syntax') loadJSON(url, (data) => { }); // And the most simplest way: (no parenthesis needed cause it's only 1 parameter) loadJSON(url, data => { }); // If you dont want to use the data optionally you can do this: loadJSON(url, () => { }); // Confusingly you can do stuff like this, it'd be better explained with a better example tho... let isTrue = check => check; let add = (a,b) => a + b; if(isTrue('true' == true)) { console.log('Yeah it's true'); } console.log(add(2,2));
@Akhaada
@Akhaada 4 года назад
I like the way you teach Sir, IMO those dislikes are from ECMA
@Shoutlikeatwebpunktd
@Shoutlikeatwebpunktd 6 лет назад
5:18 ... actually the equivalent of "function go() { }" is "var go = function() { }" and not "let go = function() { }" because functions are also hoisted...
@olatrials
@olatrials 6 лет назад
Actually, none of them are equivalent to "function go() {}", as a named function is defined as soon as its surrounding function/script is executed, while an anonymous function declared as a variable is only defined when its line is reached. go() // logs "Hello!" function go() { console.log("Hello!") } ...and go() // Uncaught TypeError: go is not a function var go = function() { console.log("Hello!") } ..and go() // Uncaught ReferenceError: go is not defined let go = function() { console.log("Hello!") }
@sadhlife
@sadhlife 6 лет назад
Ola Kaldestad okay, so it is not equivalent to var go() = function(), but this does mean that functions are hoisted, which is great!
@sampsonorson
@sampsonorson 6 лет назад
Remember it will hoist the variable "go" and not it's content (the function).
@surajkawale2763
@surajkawale2763 5 лет назад
Loving this playlist. Could u explain about closure in javascripts
@TheCodingTrain
@TheCodingTrain 5 лет назад
Does this help? ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE--jysK0nlz7A.html
@surajkawale2763
@surajkawale2763 5 лет назад
@@TheCodingTrain Awesome...sorry didn't explore ur whole channel yet...there is a lot to learn here and I'm loving it....thanks a lot again...
@Quidoute
@Quidoute 3 года назад
0:08 when I heard this sentence I feel a pro programmer not beginner anymore
@dannyblack9705
@dannyblack9705 5 лет назад
const Car = { color: red, speed: 150} Car.color = brown means that you can change style in your car as u want and as u need but cant add more space to your car or add one more door or something like this. its main idea of change const object I think
@papinkelman7695
@papinkelman7695 6 лет назад
I lime the shorts about keyword very much. Looking forward to =>. Does js has something like lambda?
@onlybrad8434
@onlybrad8434 6 лет назад
=> is the lambda
@ivanm.g.7442
@ivanm.g.7442 3 года назад
great
@arun105k
@arun105k 5 лет назад
I have a question. How do we free the memory assigned by const?
@insideTheMirror_
@insideTheMirror_ 4 года назад
Very curious what's in that sc playlist bookmark man.
@uchejaphet1344
@uchejaphet1344 4 года назад
Nice video...lively too. Do you have a video for beginners to become professionals?
@hussainwaliwali6798
@hussainwaliwali6798 6 лет назад
u just walked more KMs than I walk in a whole day
@onlybrad8434
@onlybrad8434 6 лет назад
a const object is actually making the pointer constant not the object itself. it's like the "final" in java
@TheCodingTrain
@TheCodingTrain 6 лет назад
Thanks for this clarification!
@playingwithdata
@playingwithdata 6 лет назад
"constant variable" - Ugh.
@TheCodingTrain
@TheCodingTrain 6 лет назад
ooops
@playingwithdata
@playingwithdata 6 лет назад
It's not an oops for you. It's an oops for coding terminology in general. It's just such an awkward use of language. "It's constant because it can't change, but it's a variable because that's what we call labelled values in our programs because they're things we like to change."
@grainfrizz
@grainfrizz 6 лет назад
mwtbones hahahaha
@kenhaley4
@kenhaley4 6 лет назад
mwtbones: Well, if we can say "jumbo shrimp" and "virtual reality" and "living dead," why not?
@atimoca5758
@atimoca5758 6 лет назад
The Coding Train HOW DARE YOU
@2happygamer14
@2happygamer14 5 лет назад
youre awesome
@TheNeonRaven
@TheNeonRaven 6 лет назад
Last I checked (js engines are updating all the time) const actually does not do anything as far as memory optimization vs let. Sure the possibilities are there, but that's just not how the VMs are optimized. The main reason to use const everywhere you can is so that you know a "variable" isn't going to change, which can be a problem in asynchronous code. If your program uses const everywhere that it can, then it is a red flag to other developers when they see "let", that they can assume that that variable is significant in that it is going to change.
@TheCodingTrain
@TheCodingTrain 6 лет назад
yes, yes I am learning about this now, I should have done my research more before making this video! I might redo it.
@TheNeonRaven
@TheNeonRaven 6 лет назад
No worries at all! It's still a great video and intro to ES6 variable assignment. :)
@SHRGP
@SHRGP 6 лет назад
i would like to see a video with 'class' in javascript.
@kenhaley4
@kenhaley4 6 лет назад
Great explanation, Dan, as well as the previous one about let and var. One comment: I don't think const has as much to do with performance or efficiency (if anything at all) as it does with making code clearer (by declaring, "this variable never changes") and preventing errors. By using const in a library, for example, you can prevent users of the library from inadvertently using that variable for something else, and perhaps creating very strange bugs in the library's behavior. Incidentally, "let" has its roots in the original version of BASIC; i.e., Dartmouth BASIC (see www.dartmouth.edu/basicfifty/commands.html), which is now 50 years old! I remember when it first came out. (Dating myself--I'm 70.)
@TheCodingTrain
@TheCodingTrain 6 лет назад
Wow, I love learning this about let! And yes, thank you for the comment about const and performance. I should have done my research more before making this video! I might redo it.
@kenhaley4
@kenhaley4 6 лет назад
Well, I don't know whether there's a performance benefit, I just kind of doubt it. I haven't researched it either. I'm just speaking from what I've learned about other languages. So don't redo the video--it's fine, I think. One point you might make in general: Javascript, historically, has been rather "loose," i.e., no strict data typing, no need to declare variables, etc. While that seems nice and convenient, at first it becomes very inconvenient when you have large programs or projects, as you struggle with misspelled variable names, bugs from scoping errors, etc. So, I think one of the objectives of ES6 is to rectify this. That, and improve readability and maintainability. Don't get me wrong--I love your presentations. Your style is so inviting--especially to novices--as you present complex ideas as if they're no big deal. I can see from the comments that people love it. I think the thing I like best about you is that you never hesitate to get in front of the camera and start talking and coding and white-boarding, etc., whether perfectly accurate or not. You get the point across effectively and the mistakes are forgivable because of your self-deprecating sense of humor. Nonetheless, you deliver great value, and a whale of a lot of it! I've never seen so many videos from one person. The only thing I could do without is the occasional random number readings. ;-)
@TheCodingTrain
@TheCodingTrain 6 лет назад
thank you for the nice feedback!!
@ndenkha
@ndenkha 5 лет назад
I believe the ability to change the const properties is a bug. Once a variable is declared as 'const' it should not be allowed to be changed in any way.
@angelcaru
@angelcaru 4 года назад
Make a video about "Pass by refference" and "Pass by copy"
@TheCodingTrain
@TheCodingTrain 4 года назад
Try this one! ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-hNR6fsksEu8.html
@luisschubert6438
@luisschubert6438 6 лет назад
let function aFunction(){} is not the same as function aFunction(){} as the former can only be used after it was been declared whereas the latter is defined globally
@nortoncraas4084
@nortoncraas4084 6 лет назад
Hi would it be possible for u to make a video how to set up p5 the way u have? Im having problems using p5 :(
@nortoncraas4084
@nortoncraas4084 6 лет назад
And love ur videos! I'm learning so much from them! And maybe one more thing, could u take back the timed challenges? They where so amazing!!
@goodev
@goodev 6 лет назад
Problem setting p5? Post in the Processing's forum. People will help you there.
@olatrials
@olatrials 6 лет назад
Great video as always, though I think you're putting too much emphasis on the "performance benefits" of using const. It's basically so minuscule that the two extra chars ("const" is five letters, "var"/"let" is only three) in the .js source file might very well cause a larger performance hit than what you might gain from potential memory optimisations done by the js engine. The real benefit in using const is maintainability and error handling :)
@TheCodingTrain
@TheCodingTrain 6 лет назад
Yup, this is very true! I might have to redo this video!
@Synapse-id6ej
@Synapse-id6ej 6 лет назад
In python var cat can be used in Def or class for a larger interact in one value for one topic func
@ahmadhabibi9582
@ahmadhabibi9582 3 года назад
i like you man
@franchello1105
@franchello1105 6 лет назад
Is const is like final in java?
@Bokbind
@Bokbind 6 лет назад
I believe it is. Once the variable is pointing to something, it cannot be changed in the same scope. I one major difference is you have to also initialize them to a value when declaring them, which I think you don't with Java's finals.
@18bovende
@18bovende 4 года назад
Is there a full p5.js playlist somewhere? The intro playlist only goes to 7. And this is video indicates that 16 exists...
@TheCodingTrain
@TheCodingTrain 4 года назад
If you look at all the playlists you'll find them, I wish I had a better way to organize this!
@lauriejmusic
@lauriejmusic 6 лет назад
let go
@zayanwatchel8780
@zayanwatchel8780 6 лет назад
What happens if before es6 came out some dude had var let = "something" Wouldn't that web page break?
@TheCodingTrain
@TheCodingTrain 6 лет назад
my brain just exploded
@zayanwatchel8780
@zayanwatchel8780 6 лет назад
You're welcome
@alexcsillag7816
@alexcsillag7816 6 лет назад
Why is this video not listed? I am just curious. Great video!
@TheCodingTrain
@TheCodingTrain 6 лет назад
I release the videos one at a time over time, but you can always find them in the playlists!
@dropyghost
@dropyghost 6 лет назад
Hello Dan. How come I already watch this video? did you re upload?
@TheCodingTrain
@TheCodingTrain 6 лет назад
I re-upload edited pieces of the live stream as stand-alone content, yes.
@OmarAhmad293
@OmarAhmad293 6 лет назад
anything like #define in c++ for javascript?
@TheClonerx
@TheClonerx 6 лет назад
Omar Ahmad nope
@CfarFR
@CfarFR 6 лет назад
#define is a preprocessor directive in C++, 'cause source code of C++ is compiled. A preprocessor directive is interpreted by a compiler. JavaScript is an interpreted language, so there is a compilation step called JIT by the interpreter. The compilation steps between JS and C++ aren't the sames.
@kamilbolka
@kamilbolka 6 лет назад
Could you in some point consider building using Python to build AI?
@cmdlp4178
@cmdlp4178 6 лет назад
How to set const members of an object? const this.name = "Bob"
@mikeprincivil7615
@mikeprincivil7615 3 года назад
"It's forever 50."🤣😂
@hachij_
@hachij_ 6 лет назад
"Fat arrow" if you like xD
@alexcsillag7816
@alexcsillag7816 5 лет назад
The 5 dislikers are stuck in 2014.
@JackFlashTech
@JackFlashTech 4 года назад
Lol. Disregard my comment on 16.1. Here it is.
@battlefist6884
@battlefist6884 4 года назад
next time stop dancing and try to explain things much better I came here to look the behaviour of const in for loop for(let i=0;i
@kamoroso94
@kamoroso94 6 лет назад
Another difference between var and let/const is redeclaring variables. You can do that no problem with var, but let/const will not let you redeclare the variable in the same block. But you can redeclare a let/const variable in a nested block that will hide the other variable from being changed. That's very important behavior to understand.
@TheCodingTrain
@TheCodingTrain 6 лет назад
Thanks for this clarification
Далее
16.3: ES6 Arrow Function - Topics of JavaScript/ES6
22:32
Cabeças erguidas, galera! 🙌 Vamos pegá-la!
00:10
16.1: let vs var - Topics of JavaScript/ES6
12:20
Просмотров 222 тыс.
Coding Challenge 181: Weighted Voronoi Stippling
28:59
Просмотров 156 тыс.
WHY IS THE STACK SO FAST?
13:46
Просмотров 140 тыс.
Coding Challenge 180: Falling Sand
23:00
Просмотров 805 тыс.
6.2: Classes in JavaScript with ES6 - p5.js Tutorial
20:09