Andy Hoyle
Andy Hoyle

Reputation: 846

Why was the var keyword not dropped from Typescript?

I've recently started looking at Typescript syntax. I like the more concise syntax and it feels more grown-up with support for interfaces, classes and modules.

However, when looking at variable declaration, I cannot figure out why instead of:

var x: number = 1;

They did not choose the syntax:

x: number = 1;

Why keep the var keyword?

Upvotes: 0

Views: 107

Answers (2)

Heretic Monkey
Heretic Monkey

Reputation: 12112

TypeScript is a superset of JavaScript; it merely adds syntax which is compiled to JavaScript. From the source: "TypeScript is a syntactic sugar for JavaScript. TypeScript syntax is a superset of Ecmascript 5 (ES5) syntax." So it's not going to diverge from basic JavaScript syntax.

Upvotes: 1

Sam Holder
Sam Holder

Reputation: 32936

Because typescript is a superset of javascript it is only additative and so cannot 'drop' language features that are already defined in the Ecmascript 5 syntax.

So var is here to stay.

Upvotes: 1

Related Questions