You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: 1-js/02-first-steps/06-type-conversions/1-primitive-conversions-questions/solution.md
+7-7
Original file line number
Diff line number
Diff line change
@@ -17,10 +17,10 @@ undefined + 1 = NaN // (6)
17
17
"\t\n"-2=-2// (7)
18
18
```
19
19
20
-
1.The addition with a string`"" + 1`converts`1`to a string: `"" + 1 = "1"`, and then we have`"1" + 0`, the same rule is applied.
21
-
2.The subtraction `-` (like most math operations) only works with numbers, it converts an empty string `""`to`0`.
22
-
3.The addition with a string appends the number `5`to the string.
23
-
4.The subtraction always converts to numbers, so it makes `" -9 "`a number `-9`(ignoring spaces around it).
24
-
5.`null`becomes`0`after the numeric conversion.
25
-
6.`undefined`becomes `NaN`after the numeric conversion.
26
-
7.Space characters, are trimmed off string start and end when a string is converted to a number. Here the whole string consists of space characters, such as `\t`, `\n`and a "regular" space between them. So, similarly to an empty string, it becomes `0`.
20
+
1.কোন স্ট্রিংয়ের সাথে যোগের ক্ষেত্রে`"" + 1`তে`1`রূপান্তর হয়ে `"" + 1 = "1"` হয়। তাই এখানে পায়`"1" + 0`, এক্ষেত্রেও একই নিয়ম প্রযোজ্য।
21
+
2.বিয়োগ `-` (প্রায় অন্যসব অপারেটরের মতই) শুধুমাত্র সংখ্যা নিয়ে কাজ করে, এটি ফাঁকা স্ট্রিংকে শূন্য তে রূপান্তর করে নেয় `""`থেকে`0` হবে।
22
+
3.স্ট্রিং সংযুক্তকরণ নীতি অনুসারে `5`স্ট্রিংয়ে রূপান্তর হবে।
23
+
4.বিয়োগের সময় স্ট্রিং সবসময় সংখ্যায় রূপান্তর হয়, তাই এক্ষেত্রে `" -9 "`সংখ্যা `-9`তে পরিবর্তন হয় (এখানে স্পেসগুলিকে উপেক্ষা করে )
24
+
5.`null`হবে`0`সংখ্যায় রুপান্তরের পর।
25
+
6.`undefined`হয়ে যায় `NaN`সংখ্যায় রূপান্তর করা হলে।
26
+
7.স্পেসসমূহ বাদ দেয়া হয় সংখ্যায় রুপান্তর করলে, এখানে পুরো স্ট্রিংটাই বিভিন্ন স্পেসে তৈরি, যেমনঃ `\t`, `\n`এবং তাদের মাঝের "রেগুলার" স্পেসসমূহ। সুতরাং এটি ফাঁকা স্ট্রিংয়ের মতই, যা শুন্যতে (`0`) রুপান্তর হয়।
Most of the time, operators and functions automatically convert the values given to them to the right type.
3
+
বেশীরভাগ সময়, অপারেটর ও ফাংশন সমুহ নিজে থেকেই তাদের কাছে দেয়া ভ্যালুগুলো রূপান্তর করে থাকে।
4
4
5
-
For example, `alert`automatically converts any value to a string to show it. Mathematical operations convert values to numbers.
5
+
উদাহারণ হিসাবে , `alert`নিজে থেকেই ভ্যালুকে স্ট্রিংয়ে রূপান্তর করে নেয়। অন্যদিকে, গানিতিক অপারেটরগুলি ভ্যালুকে সংখ্যায় রূপান্তর করে।
6
6
7
-
There are also cases when we need to explicitly convert a value to the expected type.
7
+
যদিও কিছু কিছু ক্ষেত্রে আমাদেরকেই ভ্যালুগুলোকে নিজেদের মত করে রূপান্তর করে নিতে হয়।
8
8
9
-
```smart header="Not talking about objects yet"
10
-
In this chapter, we won't cover objects. Instead, we'll study primitives first. Later, after we learn about objects, we'll see how object conversion works in the chapter <info:object-toprimitive>.
9
+
```smart header="এখনো অবজেক্টসমূহ নিয়ে আলোচনা হয় নি"
10
+
এই অধ্যায়ে, আমরা অবজেক্ট নয় বরং, প্রিমিটিভ বিষয়গূলো জানবো। পরবর্তিতে, অবজেক্টের ধারণা পেলে, আমরা অবজেক্ট রূপান্তর নিয়ে আলোচনা করবো। <info:object-toprimitive>.
11
11
```
12
12
13
-
## String Conversion
13
+
## স্ট্রিং রূপান্তর
14
14
15
-
String conversion happens when we need the string form of a value.
15
+
কোন ভ্যালু থেকে স্ট্রিং দরকার হলে স্ট্রিং রূপান্তর করা হয়।
16
16
17
-
For example, `alert(value)`does it to show the value.
17
+
উদাহরণ স্বরূপ, `alert(value)`ভ্যালুটিকে স্ট্রিংয়ে রুপান্তর করে নেয়।
18
18
19
-
We can also call the `String(value)`function to convert a value to a string:
19
+
আমরা একে `String(value)`ফাংশন ব্যবহার করেও স্ট্রিংয়ে রুপান্তর করতে পারিঃ
20
20
21
21
```js run
22
22
let value =true;
23
-
alert(typeof value); //boolean
23
+
alert(typeof value); //বুলিয়ান
24
24
25
25
*!*
26
-
value =String(value); //now value is a string "true"
27
-
alert(typeof value); //string
26
+
value =String(value); //এখন ভ্যালুটি একটি স্ট্রিং "true"
27
+
alert(typeof value); //স্ট্রিং
28
28
*/!*
29
29
```
30
30
31
-
String conversion is mostly obvious. A`false`becomes `"false"`, `null`becomes `"null"`, etc.
31
+
প্রায় সব স্ট্রিং রুপান্তর সুস্পষ্ট। এখানে,`false`হয়ে যায় `"false"`, `null`হয়ে যায় `"null"`, ইত্যাদি।
32
32
33
-
## Numeric Conversion
33
+
## সংখ্যা রূপান্তর
34
34
35
-
Numeric conversion happens in mathematical functions and expressions automatically.
35
+
গানিতিক ফাংশন এবং এক্সপ্রেশনের ক্ষেত্রে সংখ্যায় রুপান্তর নিজে থেকেই হয়ে থাকে।
36
36
37
-
For example, when division `/`is applied to non-numbers:
37
+
যেমন, ভাগের `/`সময় দুটি স্ট্রিং:
38
38
39
39
```js run
40
-
alert( "6"/"2" ); // 3, strings are converted to numbers
40
+
alert( "6"/"2" ); // 3, স্ট্রিংয়ের সংখ্যায় বদলে যাওয়া
41
41
```
42
42
43
-
We can use the `Number(value)`function to explicitly convert a `value`to a number:
43
+
আমরা `Number(value)`ব্যাবহার করেও স্পষ্ট করে `value`কে সংখ্যায় রূপান্তর করতে পারি:
44
44
45
45
```js run
46
46
let str ="123";
47
-
alert(typeof str); //string
47
+
alert(typeof str); //স্ট্রিং
48
48
49
-
let num =Number(str); //becomes a number 123
49
+
let num =Number(str); //সংখ্যায় 123 হয়ে গেছে
50
50
51
-
alert(typeof num); //number
51
+
alert(typeof num); //সংখ্যা
52
52
```
53
53
54
-
Explicit conversion is usually required when we read a value from a string-based source like a text form but expect a number to be entered.
54
+
স্পট করে এই রুপান্তরের পন্থাটি তখনই কাজে লাগে, যখন এমন কোন সোর্স থেকে ভ্যালু পাই, যা স্ট্রিং দেয় অথচ যেটাকে কোন সংখ্যায় দেয়ার কথা, যেমন ঃ টেক্সট ফর্ম ।
55
55
56
-
If the string is not a valid number, the result of such a conversion is `NaN`. For instance:
56
+
যদি স্টীং কোন ভ্যালিড সংখ্যা না হয়, তবে তা `NaN` হয়ে যায়। যথা:
57
57
58
58
```js run
59
59
let age =Number("an arbitrary string instead of a number");
|`string`|Whitespaces from the start and end are removed. If the remaining string is empty, the result is `0`. Otherwise, the number is "read" from the string. An error gives `NaN`.|
70
+
|<code>true ও false</code> |`1`ও`0`|
71
+
|`string`|স্ট্রিংয়ের শুরু ও শেষের স্পেস থেকে তা মুছে ফেলা হয়। বাকিটা ফাঁকা স্ট্রিং হলে, তা `0` হবে। নাহয় নাম্বারগুলি স্ট্রিং থেকে নেয়া হয়। এরর হলে `NaN` আসে।|
72
72
73
73
Examples:
74
74
75
75
```js run
76
76
alert( Number(" 123 ") ); // 123
77
-
alert( Number("123z") ); // NaN (error reading a number at "z")
77
+
alert( Number("123z") ); // NaN ("z" এর সংখ্যা রুপান্তরে এরর)
78
78
alert( Number(true) ); // 1
79
79
alert( Number(false) ); // 0
80
80
```
81
81
82
-
Please note that`null`and`undefined`behave differently here: `null`becomes zero while `undefined`becomes`NaN`.
82
+
এখানে জেনে রাখি`null`ও`undefined`এক্ষেত্রে ভিন্ন আচরণ করে: `null`হয়ে যাবে শূন্য আর `undefined`হবে`NaN`.
Almost all mathematical operations convert values to numbers. A notable exception is addition `+`. If one of the added values is a string, the other one is also converted to a string.
প্রায় সব গানিতিক অপারেটর ভ্যালুকে সংখ্যায় রূপান্তর করে নেয়। তবে উল্লেখযোগ্য একটি ব্যতিক্রম হলো যোগ `+`, যদি এর দুপাশের একটি ভ্যালুও স্ট্রিং হয় তবে অপরটিও স্ট্রিং হয়ে যাবে
86
86
87
-
Then, it concatenates (joins) them:
87
+
তখন এটি স্ট্রিংগুলাকে যুক্ত করে ফেলে:
88
88
89
89
```js run
90
-
alert( 1 + '2' ); // '12' (string to the right)
91
-
alert( '1' + 2 ); // '12' (string to the left)
90
+
alert( 1 + '2' ); // '12' (ডানপাশে স্ট্রিং)
91
+
alert( '1' + 2 ); // '12' (বামপাশে স্ট্রিং)
92
92
```
93
93
94
-
This only happens when at least one of the arguments is a string. Otherwise, values are converted to numbers.
94
+
এটা তখনই হয় যদি অন্তত একটি আর্গুমেন্ট স্ট্রিং থাকে, নাহয় তা সংখ্যায় রুপান্তরিত হয়ে যাবে।
95
95
````
96
96
97
-
## Boolean Conversion
97
+
## বুলিয়ান রূপান্তর
98
98
99
-
Boolean conversion is the simplest one.
99
+
বুলিয়ানের রূপান্তর সবচেয়ে সহজতম।
100
100
101
-
It happens in logical operations (later we'll meet condition tests and other similar things) but can also be performed explicitly with a call to`Boolean(value)`.
101
+
এটি লজিকাল এক্সপ্রেশনের ক্ষেত্রে হয় (পরবর্তিতে কণ্ডিশনাল টেস্ট সহ অন্যগুলি দেখবো) তবে এটি সুস্পট করেও রূপান্তর করা যায়`Boolean(value)`.
102
102
103
-
The conversion rule:
103
+
রূপান্তর নীতি:
104
104
105
-
-Values that are intuitively "empty", like`0`, an empty string, `null`, `undefined`, and`NaN`, become`false`.
The three most widely used type conversions are to string, to number, and to boolean.
129
+
বহুল ব্যাবহৃত ৩টি রূপান্তরসমূহ হচ্ছে স্ট্রিং ,সংখ্যায় এবং বুলিয়ানে রুপান্তর।
130
130
131
-
**`String Conversion`** -- Occurs when we output something. Can be performed with `String(value)`. The conversion to string is usually obvious for primitive values.
131
+
**`স্ট্রিংয়ে রূপান্তর`** -- আউটপুট দেখতে হলে হয়। অথবা `String(value)` দিয়ে করা যায়। প্রায় সব মৌলিক ভ্যালুর জন্য এটা খুব স্পষ্ট।
132
132
133
-
**`Numeric Conversion`** -- Occurs in math operations. Can be performed with `Number(value)`.
133
+
**`সংখ্যায় রূপান্তর`** -- গানিতিক অপারেশনে হয়। `Number(value)` দিয়েও করতে পারি।
134
134
135
-
The conversion follows the rules:
135
+
রূপান্তর নীতি:
136
136
137
-
| Value | Becomes... |
137
+
| ভ্যালু | বদলে যায়... |
138
138
|-------|-------------|
139
139
|`undefined`|`NaN`|
140
140
|`null`|`0`|
141
141
|<code>true / false</code> | `1 / 0` |
142
-
| `string` | The string is read "as is", whitespaces from both sides are ignored. An empty string becomes `0`. An error gives `NaN`. |
142
+
| `string` | স্ট্রিংয়ে যা তাই আসে, স্ট্রিংয়ের শুরু ও শেষের স্পেস থেকে তা মুছে ফেলা হয়। বাকিটা ফাঁকা স্ট্রিং হলে, তা `0` হবে। নাহয় নাম্বারগুলি স্ট্রিং থেকে নেয়া হয়। এরর হলে `NaN` আসে। |
143
143
144
-
**`Boolean Conversion`** -- Occurs in logical operations. Can be performed with `Boolean(value)`.
144
+
**`বুলিয়ানে রূপান্তর`** -- লজিকাল অপারেশনে হয়। আবার `Boolean(value)` দিয়েও করা যায।
145
145
146
146
Follows the rules:
147
147
148
-
| Value | Becomes... |
148
+
| ভ্যালু | বদলে যায়... |
149
149
|-------|-------------|
150
150
|`0`, `null`, `undefined`, `NaN`, `""` |`false`|
151
-
|any other value| `true` |
151
+
|অন্য যেকোন ভ্যালু| `true` |
152
152
153
153
154
-
Most of these rules are easy to understand and memorize. The notable exceptions where people usually make mistakes are:
154
+
প্রায় সব নীতিই বুঝা অ মনে রাখা সোজা। তবে কিছু কমন ভুল হলো:
155
155
156
-
- `undefined` is `NaN` as a number, not `0`.
157
-
- `"0"` and space-only strings like `" "` are true as a boolean.
156
+
- `undefined` হয় `NaN` সংখ্যা হিসাব করলে, `0` নয়
157
+
- `"0"` ও স্পেস `" "` বুলিয়ানে true
158
158
159
-
Objects aren't covered here. We'll return to them later in the chapter <info:object-toprimitive> that is devoted exclusively to objects after we learn more basic things about JavaScript.
159
+
অবজেক্ট এখানে কভার করা হয় নি। আমরা এখানে আবার আসবো। <info:object-toprimitive> এটা শুধুই অব্জেক্টের জন্য যখন আমরা আরো ভালো করে জাভাস্ক্রিপ্ট শিখে ফেলবো.
0 commit comments