Why JavaScript in MakeCode don't accept var?

const and let are allowed as declaring variables, except for var, in modified JavaScript. var is used to declare a variable, but you can redeclare it with this. You can use var with something like:

var jello = 3
var jello = 5
console.log(jello)

const and let work similarly, but you cannot redeclare, only change the value, but with const, you cannot change the value and redeclare it. Here is an example:

let jello = 5
console.log(jello)
let jello = 3 // Returns an error: Cannot redeclare block-scoped variable 'jello'.

const drink = 9
drink = 3 // Returns an error: Cannot assign to 'drink' because it is a constant or a read-only property. 

But here’s the big question: why does MakeCode’s JavaScript never accept var? I was wondering if they were useless, but I think it makes it less flexible, which is problematic. Any ideas, guys?

1 Like

MakeCode does not use JavaScript. Rather, it uses TypeScript (and, to be precise, a variant called static TypeScript). The use of var is heavily discouraged in TypeScript.

4 Likes