Declaring variables in ES6

We don’t use the var keyword in ES6 anymore to declare variables:

var name = 'John'

Instead we have the “let” and “const” keywords for this purpose. With “let” we declare variables whose value can change over time:

let age = 30

…whereas const indicates a variable whose value is not expected to change:

const name = 'John'

We cannot reassign the name variable after this point:

name = 'Bill'

…will result in an error:

TypeError: Assignment to constant variable.

Constant variables must also be given a value immediately. The following is invalid:

const name
name = 'John'

View all posts related to JavaScript here.

Unknown's avatarAbout Andras Nemes
I'm a .NET/Java developer living and working in Stockholm, Sweden.

Leave a comment

Elliot Balynn's Blog

A directory of wonderful thoughts

Software Engineering

Web development

Disparate Opinions

Various tidbits

chsakell's Blog

WEB APPLICATION DEVELOPMENT TUTORIALS WITH OPEN-SOURCE PROJECTS

Once Upon a Camayoc

ARCHIVED: Bite-size insight on Cyber Security for the not too technical.