Here uses let ,there uses const ,why


#1

let Airplane={};
module.exports = {
myAirplane :“CloudJet”,
displayAirplane: function(){
return this.myAirplane;
}
};

const Airplane=require(’./2-airplane.js’);

hi everyone
my question is the same variable Airplane ,which is used in the same programme ,but at html ,we use ‘let’,
but at js ,we use ‘const’,why ?
thanks


#2

deciding if you want to use let or const is a decision made by the programmer, okay, maybe not yet in the codecademy exercises, but you are still learning.

const (which is short for constant) variable can’t be change/updated/re-assigned, so if you do:

const example = "hello world"
example = "this will give an error"

with other words, when we define Airplane variable on line 1, we know it still needs changing, so we use let (let does allow for the variable to get re-assigned)


#3

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.