-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtypes.js
More file actions
66 lines (50 loc) · 1.46 KB
/
Copy pathtypes.js
File metadata and controls
66 lines (50 loc) · 1.46 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
66
// variable declarations
var name = 'arvind'; // when we declare var we can access it from any where, it can be reassigned
const name1 = 'arvind 2'; // can't be reassigned
let name2 = 'arvind 2'// block scope, can be reassigned
const userName = 'ARVIND_1234';
function printer() {
let age = 29;
console.log(userName, age);
}
printer();
/**
* js defines seven build-in types
* null
* undefined
* boolean
* number
* string
* object
* symbol - added in ES6
*/
// typeof -> return the type of variable or value
console.log(typeof 54 === 'number'); // number
console.log(typeof 'hello' === 'string'); // string
console.log(typeof { name: 'arvind' } === 'object'); // object
console.log(typeof true === 'boolean'); // boolean
console.log(typeof Symbol() === 'symbol');
let age = 29;
if (typeof age === 'number') {
console.log('age is number');
}
console.log(!isNaN(age));
let active = true;
if (active) {
console.log('user is active');
};
let undefinedValue;
console.log(undefinedValue);
/**
* variable declare
* 1. var -> old
* 2. let -> can be changed or reassigned
* 3. const -> can't be change once assigned
*/
var a; // without assignment it's undefined
console.log('printing type of var a', typeof a); // undefined
console.log('printing type of var b', typeof b); // undefined
var nullValue = null; // falsy value
console.log('printing type of var nullValue', typeof nullValue); // object
console.log(nullValue); // null
console.log(!nullValue); // true