What changes is the scope in which the variable can be reached, and if it is constant (cannot be reassigned.
var name = 'Joe'let name = 'Joe'const name = 'Joe'Use only let or const whenever possible. Initialize it as a const and if a reassignment is needed further on, change it to a let.
This:
var name = 'Joe';
const welcome = 'Welcome ' + name + '!'; // Concatenation
Is now This:
const name = 'Joe';
const welcome = `Welcome ${name}!`; // Interpolation
`` // Any String
${} // Any JS Code to interpolate
; // Break line
const foo = `Any string text; ${1 + 1}; ${2 + 2}`;
This:
function welcome(name) {
var message = 'Welcome ' + name + '!';
return message;
}
Is now This: