Variables label and store data in memory. There are only a few things you can do with variables:
It is important to distinguish that variables are not values; they contain values and represent them with a name
Pre ES6
ES6
Using let: allows reassignment with different values, holds undefined without initialization.
When using let (and even var), we can declare a variable without assigning the variable a value.(Will hold undefined value) Meaning, let 이나 var 변수는 initilize 할필요 없이 변수 생성 가능.
Using const: cannot be reassigned. Must be innitialzed or assigned when declared.
It does not mean the value it holds is immutable—just that the variable identifier cannot be reassigned.
If you’re trying to decide between which keyword to use, let or const, think about whether you’ll need to reassign the variable later on. If you do need to reassign the variable use let, otherwise, use const.
Global constants do not become properties of the window object, unlike var variables.
let w = 4;
w = w + 1;
console.log(w); // Output: 5
//Use of built in mathmetical assignment operators
let w = 4;
w += 1;
console.log(w) // Output: 5
*The increment operator will increase the value of the variable by 1. The decrement operator will decrease the value of the variable by 1. For example:
let a = 10;
a++;
console.log(a); // Output: 11
let b = 20;
b--;
console.log(b); // Output: 19
let myPet = 'armadillo';
console.log('I own a pet ' + myPet + '.');
Interporation: In the ES6 version of JavaScript, we can insert, or interpolate, variables into strings using template literals.
One of the biggest benefits to using template literals is the readability of the code. Also not having to worry about escaping double quotes or quotes.
const unknown1 = 'foo';
console.log(typeof unknown1); // Output: string
const unknown2 = 10;
console.log(typeof unknown2); // Output: number
const unknown3 = true;
console.log(typeof unknown3); // Output: boolean