This repository was archived by the owner on May 16, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvariable.js
More file actions
66 lines (54 loc) · 1.4 KB
/
Copy pathvariable.js
File metadata and controls
66 lines (54 loc) · 1.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
//1.Use strict
// added in ES 5
// use this for Javascript
"use strict";
console.log(age);
//2.Variable
//let (added in ES6)
let globalName = "global name";
{
let name = "ellie";
console.log(name);
name = "hello";
console.log(name);
console.log(globalName);
}
console.log(name);
console.log(globalName);
// var (don't ever use this!)
// var hoisting (move declaration from bottom to top)
// has no block scope
{
age = 4;
var age;
}
console.log(age);
// 3.constants
// favor immutable data type always for a few reasons:
// - security
// - threead safety
// - reduce human mistakes
const daysInWeek = 7;
const maxNumber = 5;
//4. Variable types
//primitive, single item: number, string, boolean, null, undefined, symbol
// object, box container
// function, first-class function
const count = 17; //integer
const size = 17.1; // decimal number
console.log(`value:${count}, type:${typeof count}`);
console.log(`value:${size}, type:${typeof size}`);
// number - special numeric values: infinity, -infinity, NaN
const infinity = 1 / 0;
const negativeInfinity = -1 / 0;
const nAn = "not a number" / 2;
console.log(infinity);
console.log(negativeInfinity);
console.log(nAn);
//bigInt (fairly new, don't use it yet)
const bigInt = 12345678902345679234235547756735245n;
console.log(`value:${bigInt}, type: ${typeof bigInt}`);
//string
const char = 'c';
const brendan = 'bendan';
const greeting = 'hello' + brendan;