Basics

Challenges

Classes

Cookies

Debugging

Events

External Files

Flow Control

Forms

Functions

Html Elements

Installation

Interfaces

Keywords

Modules

Namespaces

Operators

Reference Files

String

Types

TypeScript - const

const values cannot be changed once they are bound. In other words, they have the same scoping rules as let, but you can’t re-assign to them.

readonly is a keyword that can only be used in a class. A const can be used anywhere.

The easiest way to remember whether to use readonly or const is to ask whether you’re using it on a variable or a field/property.

Variables use const whereas fields/properties use readonly.


const _message: string = "Hello World";

window.onload = function ()
{
    let messageLabel = <HTMLElement>document.getElementById("message-label");
    messageLabel.innerHTML = _message;

    // notice that you cannot reassign this.
    //_message = "new text here";
    //messageLabel.innerHTML = _message;
};

 

https://www.typescriptlang.org/docs/handbook/variable-declarations.html