# JS Tip of the Day: Declarations let, const and class Can’t be Redeclared

**URL:** <https://forum.kirupa.com/t/js-tip-of-the-day-declarations-let-const-and-class-can-t-be-redeclared/643169>\
**Category:** web dev\
**Created:** [February 27, 2020, 12:39pm UTC](https://forum.kirupa.com/t/js-tip-of-the-day-declarations-let-const-and-class-can-t-be-redeclared/643169 "2020-02-27T12:39:00Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![senocular](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/senocular/32/7217_2.png) [@senocular](https://forum.kirupa.com/u/senocular)\
**Post date:** [February 27, 2020, 12:39pm UTC](https://forum.kirupa.com/t/js-tip-of-the-day-declarations-let-const-and-class-can-t-be-redeclared/643169/1 "2020-02-27T12:39:00Z")

</div>

**Declarations let, const and class Can’t be Redeclared**  
Version: ES2015  
Level: Beginner

When declaring variables with `let`, `const`, and `class`, you’ll need to be sure not to duplicate declarations of the same name in the same scope. Doing so will create an error.

```javascript
let num = 1;
let num = 2;
// SyntaxError: Identifier 'num' has already been declared

```

This is not the case with `var` and `function` declarations. They can be repeated without producing an error.

```javascript
var num = 1;
var num = 2; // Ok, num = 2

```

If you mix these declarations, for example using both `let` and `var` with the same identifier name, the `let` behavior will be used; that is, the redeclaration will not be allowed.

```javascript
var num = 1;
let num = 2;
// SyntaxError: Identifier 'num' has already been declared

```

You _can_ redeclare variables of the same name in different scopes, even if just an arbitrary block scope (when using `let`, `const`, and `class` which are block scoped).

```javascript
let num = 1;
{
    let num = 2; // Ok, no conflict
}

```

Note: As of Chrome version 80, you can also redeclare `let` and `class` in multiple entries within the JavaScript console without there being an error. Attempting to redeclare a `const`, however, will still produce a SyntaxError.

More info:

- [let on MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/let)
- [var on MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/var)
- [Chrome 80 let and class in Console](https://developers.google.com/web/updates/2019/12/devtools#redeclarations)
