-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtypeConversion.js
More file actions
37 lines (25 loc) · 995 Bytes
/
typeConversion.js
File metadata and controls
37 lines (25 loc) · 995 Bytes
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
//typeConversion
//change one datatype to another
const { loadavg } = require("os");
//types of type conversion
// 1. type casting (Explicit)
// 2. type coersion(Implicit)
//type casting
// it is explicit means it is coverted manually that controlled by programmer using some methods like Number(), Boolean () , toString()
let name = "salman";
console.log(typeof name); // string
let changedname = Boolean("name");
//or we can use !! name
console.log(typeof changedname);// Number
//type coersion
// it is implicit . it is automatically converted datatype by js
// to string
console.log("5" + 1); // number to string => "51"
console.log(true + "!") // boolean to string => "true!"
console.log(null + "abc") // null to string => "nullabc"
// to number
console.log("51" * 1)// string to number => 51
console.log(true - 1)// boolean to number (true is value 1 is default) => 0
console.log(null + 1)// null to number => 1
//to boolean
// every if() and while .conditional operators