# 01_JavaScript : Variables & Operators

`Vanilla JavaScript` : pure JavaScript without any libraries

1. Chrome Inspect
    
2. Codesandbox ([https://codesandbox.io](https://codesandbox.io))
    

---

Ex01. `console.log();`

```javascript
console.log(1+2+3+4);
console.log('Hello');
```

---

Ex02. `let`

```javascript
let value = 1; 
console.log(value); // 1
value = 2;
console.log(value); // 2
```

(\* we don't use `var` any more)

Ex03. `const`

```javascript
const a = 1;
a = 2; // Error
```

Ex04. `Number` / `String` / `Boolean` / `Null` / `Undefined`

```javascript
let value = 1; // Number
let text = 'hello'; // String (Double or single quotation marks) 
let good = true; // boolean
const friend = null // null : literally empty on purpose
let criminal // undefined
```

---

Ex05. `Arithmetic Operators`

```javascript
let a = 1 + 2;
console.log(a); //3
a++;
++a;
console.log(a); //5
console.log(a++); //5 -> 6 on the next line
console.log(++a); //7
```

Ex06. `Assignment Operators`

```javascript
let a = 1;
a = a + 3;
let b = 5;
b += 3;
b -= 3;
b *= 3;
b /= 3;
```

Ex07. `Boolean Operators`

* `!` : Not
    
* `&&` : AND
    
* `||` : OR
    

```javascript
const a = !true; //false
const b = !false; //true

const c = true && false //false
const d = true || false //true

const value = !((true && false) || (true && false) || !false); // left to right 
// !(false || false || true) 
// !(true)
// false
```

Ex08. `Comparison Operators(1)`

* `==`
    
* `===` : Type Check! (\*recommendation)
    
* `!=`
    
* `!==` : Type Check!
    

```javascript
const a = 1;
const b = '1';
const equals_01 = a == b; //true
const equals_02 = a === b; //false
```

```javascript
const a = 0;
const b = false;
const equals = a == b; // true : 0 and false are same here
```

```javascript
const a = null;
const b = undefined;
const equals = a == b; // true : null and undefined are same here
```

```javascript
const value = 'a' !== 'b'; // true
console.log(1 != '1'); // false
console.log(1 !== '1'); // true
```

Ex09. `Comparison Operators(2)`

* `<`, `>`, `<=`, `>=`
    

```javascript
const a = 10;
const b = 15;
const c = 15;

console.log(a < b); // true
console.log(b > a); // true
console.log(b >= c); // true
console.log(a <= c); // true
console.log(b < c); // false
```

---

Ex10. `(concatenate) Merge Arrays`

* str1 `+` str2
    

```javascript
const a = 'Hi, ';
const b = 'This is Dana';
console.log(a+b); //Hi, This is Dana
```

---

Ex11. `Ternary Operators`

```javascript
const array = [];
let text = array.length === 0 ? '배열이 비어있습니다' : '배열이 비어있지 않습니다.';
// you can directly assign 
console.log(text);
```

---

cf. [https://learnjs.vlpt.us/basics/02-variables.html](https://learnjs.vlpt.us/basics/02-variables.html)
