Code Monkey home page Code Monkey logo

let-const's Introduction

ES5 Global Constants

var PI = 3.14;
PI = 42; // stop me from doing this!

ES2015 Global Constants

/* Write an ES2015 Version */
let PI = 3.14;
PI = 42;
///Uncaught SyntaxError: Identifier 'PI' has already been declared

Quiz

What is the difference between var and let?

var allows you to redeclare, while let prevents this. var is used within a function scope and let is relative to the block.

What is the difference between var and const?

var can be reassigned and redeclared while const cannot. var is used in a function scope while const is relative to the block scope.

What is the difference between let and const?

let can be reassigned to a new variable while const cannot.

What is hoisting?

Hoisting is a process in javascript in which both functions and variables are put to the top of the corresponding scope during compilation.
This happens usually if you reference a variable in a function before it is declared - and the variable is declared before the function calls that specific variable.
One important note is that the variable is only declared but not initialized, meaning that the code accessing it before initialization will be working with an undefined.
Hoisted functions can be called before definition but function expressions (setting a function to a a variable expression) are not, resulting in an error.

let-const's People

Contributors

blinter avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.