16.2: const – Topics of JavaScript/ES6

[ad_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”:

Support this channel on Patreon:
To buy Coding Train merchandise:
To Support the Processing Foundation:

Send me your questions and coding challenges!:

Contact:
Twitter:
The Coding Train website:

Source Code for the all Video Lessons:

p5.js:
Processing:

For an Intro to Programming using p5.js:
For Coding Challenges:


Posted

in

by

Tags:

Comments

33 responses to “16.2: const – Topics of JavaScript/ES6”

  1. limzykenneth Avatar

    3:30 to explain being able to change values of object, especially coming from another programming language: const in JS does NOT make the value/variable immutable, what it does is to prevent redefinition of the variable, the value it is assigned to can change. Understanding this will help with understanding how pointers and reference work in JS.

  2. Luis Schubert Avatar

    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

  3. Dane Calderon Avatar

    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!

  4. HABELFOC _ Avatar

    "Fat arrow" if you like xD

  5. cmdLP Avatar

    How to set const members of an object?

    const this.name = "Bob"

  6. Allan Yde Avatar

    Hi Daniel! πŸ™‚

    Would you make a tutorial on how on how to use the sound library in Processing.

    How the oscillators, envelopes and etc. works.

  7. Scythic Avatar

    thank you for the video and its useful information. I'd be glad if you also explain "=>"

  8. Hamdi Rizal Avatar

    Your videos are really fun to watch. Please make more video about learning javascript. πŸ™‚

  9. Newb Programming Avatar

    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));

  10. Scott MacDonald Avatar

    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.

  11. Ken Haley Avatar

    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 http://www.dartmouth.edu/basicfifty/commands.html), which is now 50 years old! I remember when it first came out. (Dating myself–I'm 70.)

  12. G' Squared Avatar

    You could also make a video about parameter defaults. Those are kinda cool.

  13. benjhabert Avatar

    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"

  14. Sworn Avatar

    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.

  15. Ola Kaldestad Avatar

    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 πŸ™‚

  16. alekmoth Avatar

    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.

  17. shoutlike Avatar

    5:18 … actually the equivalent of "function go() { }" is "var go = function() { }" and not "let go = function() { }" because functions are also hoisted…

  18. Norton Craas Avatar

    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 πŸ™

  19. Kamil Bolka Avatar

    Could you in some point consider building using Python to build AI?

  20. nononononononononnononononon Avatar

    i would like to see a video with 'class' in javascript.

  21. mwtbones Avatar

    "constant variable" – Ugh.

  22. Pa Pinkelman Avatar

    I lime the shorts about keyword very much.
    Looking forward to =>.
    Does js has something like lambda?

  23. Frank Rodriguez Avatar

    Is const is like final in java?

  24. kubimogero Avatar

    Looking forward watching arrow syntax!

  25. TMCicuurd12b42 Avatar

    const can protect your code from yourself and can protect your code from hacking I guess.
    for example I've been hacking slither.io's grabbling the original methods and replacing them with mine

    //Grabbing the update function
    oldUpdate = window.update
    //Replace with mine
    window.update = function () {
    //do my thing
    DoMyThings();
    //call original
    oldUpdate();
    }

  26. ninja_brutal Avatar

    In python var cat can be used in Def or class for a larger interact in one value for one topic func

  27. Filip Krawczyk Avatar

    Const is very useful in node.js for including libraries. Eg.: const fs = require ('fs') // filesystem module

  28. dwhxyz Avatar

    If your starting to discuss ES6 then it might be helpful to do a couple of videos on TypeScript. Btw, love your videos πŸ˜€

  29. Omar Ahmad Avatar

    anything like #define in c++ for javascript?

  30. Sophia Kornienko Avatar

    I think:
    “`
    const y;
    y = 100;
    “`
    will fail.
    The error will be: `Missing assignment in const declaration.`

  31. Csillag Alex Avatar

    Why is this video not listed? I am just curious. Great video!

Leave a Reply

Your email address will not be published. Required fields are marked *