Seamus  Quitzon

Seamus Quitzon


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

You will find these keywords, valvarletconststatic, and defused 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 mutate the value
console.log(x)  // result 11

Recreate the variable (a no-no in the other languages)

// JavaScript
var x = 10
var x = 11      // this is okay
console.log(x)  // result 11

Accessibly outside the scope (a no-no in the other languages)

// JavaScript
function test() {
        var x = 10
    console.log(x)  // accessible and result is 10

Note, it can’t be accessed outside the function though. Therefore it is also called a function scoped variable.

Attached to the window if defined at global scope

This means if it is defined at the global scope, it will stick to the window

var stickyVariable = 10
window.stickyVariable    // available in window and result as 10

Using this type variable is pretty risky as it easily gets mutated and can affect and be affected by 3rd party libraries variable setting if the name collide. It is there as pre ES6, that’s the way JavaScript has its variable defined.

A normal mutable variable

When I term normal, I mean the life of the variable is limit within the scope where it is defined i.e. { /* scope is covered by curley brackets */ }.

A mutable variable is a variable that CAN be changed (reassigned) with a new value after being created.

  • In Swift, Kotlin, and Scala, they are named var.
  • However, in JavaScript, it is named let.

After a variable has been created, it cannot be created anymore

// JavaScript
let x = 10
let x = 11     // Error: Identifier 'x' has already been declared

However, it can be reassigned

// JavaScript
let x = 10
x = 11          // this is okay
console.log(x)  // result 11

A normal immutable variable

When I term normal, I mean the life of the variable is limit within the scope where it is defined i.e. { /* scope is covered by curley brackets */ }.

An immutable variable is a variable that CANNOT be changed (reassigned) with a new value after being created.

  • In Kotlin and Scala, they are named var.
  • In Swift, it is named as let (don’t mix up with the let in JavaScript).
  • In JavaScript, it is named as const
// JavaScript
const x = 10
x = 11        // Assignment to constant variable

#software-development #web-development #programming #software-engineering #mobile-app-development #mobile-app

What is GEEK

Buddha Community

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

JavaScript Var, Let, and Const - 8

To declare a variable in JavaScript either var, let or const is used.
We will distinguish between the three with the following features:

  • Block scope
  • Update and redeclaration
  • Hoisting
  • Undefined

Official Website:

Watch the entire JavaScript Series, including upcoming JavaScipt videos on YouTube:

Check it out on the article:

Become a patron to learn more:


Techstack Media is in partnership with Skillshare:
Learn anything and get the required skill you need to kickstart a long-lasting career.

Website Request:

Social Media:
✅ Facebook:
✅ Twitter:
✅ Instagram:
✅ LinkedIn:

#javascriptdatatypes #javascipthoisting #javascriptvariable #techstackmedia #webdev #DEVCommunity #100DaysOfCode #opensource #codenewbies #womenwhocode #html #webdevelopment

#javascript #javascript var #let #const

Eldora  Bradtke

Eldora Bradtke


JavaScript Variables: var and let and const

There are three ways to create variables in a JavaScript application: using var, using let, or using const. This will not be a post trying to convince you which one you should use, or arguing about what is best. It’s just good to know about the differences and what it means when you use the different options. But hopefully by the end of all this you’ll be comfortable with the three options and can make a decision for your team that will suit your needs. To get the most out of this post, it is best if you understand variable scope, which we covered in this post previously.

#javascript #var #let #const

Tanya  Shields

Tanya Shields


Declaring A Winner Between JavaScript's var, let And const

When ECMAScript 6 (also known as ECMAScript 2015) was released a collection of new APIs, programming patterns and language changes became a standard. Since ES6 started gaining browser and nodejs support developers are wondering if they should stop using the traditional var to declare variables.
ES6 introduced two new ways to declare variables, let and const.

var - has function level scoping and can change the value reference
let - has block level scoping and can change the value reference
const - has block level scoping but cannot change the value reference
Both provide better block scoping that var. const differs from let because the immediate value cannot be changed once it is declared.
Variables declared using var are function scoped, which has led to confusion to many developers as they start using in JavaScript.

#javascript #var #let #const #programming

Eldora  Bradtke

Eldora Bradtke


JavaScript Variables Explained. Var, Let and Const with examples.

Before the arrival of ES6 or EcmaScript 6 released in 2015, as a Javascript developer, you could only declare variables using the var keyword.
Now things has changed and two new keywords have been introduced to meet the developers needs who felt the old one way solution very tight for the modern web app requirements.
In this article I will try to explain you in the simplest way possible, the differences between var, let and const type variables.
I think the best way to do this is to try to extrapolate the essence of their nature by describing them in few words followed by examples which gives you the confirmation and consolidation of what you learned in the theory.
Like many other programming languages, JavaScript has variables. I talk you through var, let and const, and how they differ from each other with the use of some simple examples.

#javascript #var #let #const #programming

Dexter  Goodwin

Dexter Goodwin


A Simple Explanation Of JavaScript Variables: Const, Let, Var

The variable is a fundamental concept that any developer should know.

In JavaScript, constlet, and var are the statements you can declarate variable.

I’m going to describe each variable type around the declaration, initialization, value access, and assignment. Each of the 3 types (constlet, and var) create variables that behave differently exactly in these 4 steps.

This post isn’t quite beginner friendly, but rather useful to solidify your knowledge of variables and their behavior.

Let’s get started.

1. Variable identifier

First, let’s understand what a variable is.

In simple terms, a variable is a placeholder (or a box) for a value. A value in JavaScript can be either a primitive value or an object.

The variable has a name, which stricter is called identifier. Examples of identifiers are myNumbernamelistitem.

The syntax of an identifier is pretty simple:

An identifier can contain letters, digits 0..9, and special symbols $_. An identifier cannot start with a digit 0..9.

Examples of valid identifiers are myNumbermy_numberlist1$item_nameab$_.

#javascript #variable #const #let #var