Cross Programming Languages Learning

Val, Var, Let, Const, Static, and Def across JavaScript, Swift, Kotlin, and Scala

The same keyword but could be of different meaning

Elye - A One Eye Dev By His Grace
The Startup
Published in
5 min readJun 26, 2020

--

Photo by Henry Lorenzatto on Unsplash

You will find these keywords, val, var, let, const, static, and def used across these languages to define a variable, i.e. JavaScript, Swift, and Scala, as seen below.

A simple thinking is that if the keyword is the same, then the behavior is the same across the languages. Unfortunately, they are of different meanings sometimes.

Hence I’m writing here to share about them for a quick comparison.

A rogue mutable variable

This is the var in JavaScript, that is unique to this “wild-wild west” language that can do almost anything. No other languages (above) has this attribute, except for JavaScript.

Below are some very interesting attributes it has.

Assign and Mutate (okay, this is not interesting)

// JavaScript
var x = 10
x = 11 // reassign to…

--

--