Skip to content

Commit fe42344

Browse files
authored
Update 13-typeconversion.md
1 parent d9604ae commit fe42344

File tree

1 file changed

+16
-16
lines changed

1 file changed

+16
-16
lines changed

notes/English/13-typeconversion.md

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,19 @@ In case the behavior of the implicit conversion is not sure, the constructors of
1010

1111
The Number 10 is converted to string '10' and then '+' concatenates both strings
1212

13-
```
13+
```javascript
1414
var x = 10 + "20";
1515
var y = "20" + 10;
1616
```
1717

1818
### The Boolean value true is converted to string 'true' and then '+'concatenates both the strings
1919

20-
```
20+
```javascript
2121
var z = true + "10";
2222
console.log(x, y, z); //1020 2010 true10
2323
```
2424

25-
```
25+
```javascript
2626
var w = 10 - "5";
2727
var x = 10 * "5";
2828
var y = 10 / "5";
@@ -33,65 +33,65 @@ console.log(w, x, y, z); //5 50 2 0
3333

3434
### The Boolean value true is converted to number 1 and then operation is performed
3535

36-
```
36+
```javascript
3737
var x = true + 2;
3838
```
3939

4040
### The Boolean value false is converted to number 0 and then operation is performed
4141

42-
```
42+
```javascript
4343
var y = false + 2;
4444

4545
console.log(x, y); // 3 2
4646
```
4747

4848
### Should output 'true' as string '10' is coerced to number 10
4949

50-
```
50+
```javascript
5151
var x = 10 == "10";
5252
```
5353

5454
### Should output 'true', as boolean true is coerced to number 1
5555

56-
```
56+
```javascript
5757
var y = true == 1;
5858
```
5959

6060
### Should output 'false' as string 'true' is coerced to NaN which is not equal to 1 of Boolean true
6161

62-
```
62+
```javascript
6363
var z = true == "true";
6464

6565
console.log(x, y, z); //true true false
6666
```
6767

6868
### Number to String
6969

70-
```
70+
```javascript
7171
let ans = String(10);
7272
console.log(typeof ans); //string
7373
```
7474

7575
### String to Number
7676

77-
```
77+
```javascript
7878
ans = Number("10");
7979
console.log(ans); //number
8080
```
8181

82-
```
82+
```javascript
8383
ans = Number("learnjavascript");
8484
console.log(ans); //NaN
8585
```
8686

8787
### Number to Boolean
8888

89-
```
89+
```javascript
9090
ans = Boolean(10);
9191
console.log(ans); //true
9292
```
9393

94-
```
94+
```javascript
9595
ans = Boolean(0);
9696
console.log(ans); //false
9797
```
@@ -105,19 +105,19 @@ implicit type conversion me javascrupt otomatic ak type se dusri type me convert
105105
number se string me conversion
106106
string se number me convrsion
107107

108-
```
108+
```javascript
109109
let x = "20";
110110
console.log(x / 2);
111111
```
112112

113113
### Explicit type and manual type conversion
114114

115-
```
115+
```javascript
116116
let x = "20";
117117
console.log(Number(x) + 20); // //string to number
118118
```
119119

120-
```
120+
```javascript
121121
let y = 10;
122122
console.log(string(y) + 200); //number to string
123123
```

0 commit comments

Comments
 (0)