Skip to content

Commit c8c8cb4

Browse files
author
Md. Jamal Uddin
authored
Merge pull request #9 from AshiqueImran/master
Type Conversions
2 parents 07ce6df + 900f7db commit c8c8cb4

File tree

3 files changed

+70
-70
lines changed

3 files changed

+70
-70
lines changed

Diff for: 1-js/02-first-steps/06-type-conversions/1-primitive-conversions-questions/solution.md

+7-7
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@ undefined + 1 = NaN // (6)
1717
" \t \n" - 2 = -2 // (7)
1818
```
1919

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`) রুপান্তর হয়।

Diff for: 1-js/02-first-steps/06-type-conversions/1-primitive-conversions-questions/task.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ importance: 5
22

33
---
44

5-
# Type conversions
5+
# টাইপ রূপান্তর
66

7-
What are results of these expressions?
7+
এক্সপ্রেশনগুলির ফলাফল কী হবে?
88

99
```js no-beautify
1010
"" + 1 + 0
@@ -24,4 +24,4 @@ undefined + 1
2424
" \t \n" - 2
2525
```
2626

27-
Think well, write down and then compare with the answer.
27+
ভালো করে ভাবুন, লিখে রাখুন এবং আমদের উত্তরের সাথে মিলিয়ে দেখুন।

Diff for: 1-js/02-first-steps/06-type-conversions/article.md

+60-60
Original file line numberDiff line numberDiff line change
@@ -1,111 +1,111 @@
1-
# Type Conversions
1+
# টাইপ রূপান্তর
22

3-
Most of the time, operators and functions automatically convert the values given to them to the right type.
3+
বেশীরভাগ সময়, অপারেটর ও ফাংশন সমুহ নিজে থেকেই তাদের কাছে দেয়া ভ্যালুগুলো রূপান্তর করে থাকে।
44

5-
For example, `alert` automatically converts any value to a string to show it. Mathematical operations convert values to numbers.
5+
উদাহারণ হিসাবে , `alert` নিজে থেকেই ভ্যালুকে স্ট্রিংয়ে রূপান্তর করে নেয়। অন্যদিকে, গানিতিক অপারেটরগুলি ভ্যালুকে সংখ্যায় রূপান্তর করে।
66

7-
There are also cases when we need to explicitly convert a value to the expected type.
7+
যদিও কিছু কিছু ক্ষেত্রে আমাদেরকেই ভ্যালুগুলোকে নিজেদের মত করে রূপান্তর করে নিতে হয়।
88

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>.
1111
```
1212

13-
## String Conversion
13+
## স্ট্রিং রূপান্তর
1414

15-
String conversion happens when we need the string form of a value.
15+
কোন ভ্যালু থেকে স্ট্রিং দরকার হলে স্ট্রিং রূপান্তর করা হয়।
1616

17-
For example, `alert(value)` does it to show the value.
17+
উদাহরণ স্বরূপ, `alert(value)` ভ্যালুটিকে স্ট্রিংয়ে রুপান্তর করে নেয়।
1818

19-
We can also call the `String(value)` function to convert a value to a string:
19+
আমরা একে `String(value)` ফাংশন ব্যবহার করেও স্ট্রিংয়ে রুপান্তর করতে পারিঃ
2020

2121
```js run
2222
let value = true;
23-
alert(typeof value); // boolean
23+
alert(typeof value); // বুলিয়ান
2424

2525
*!*
26-
value = String(value); // now value is a string "true"
27-
alert(typeof value); // string
26+
value = String(value); // এখন ভ্যালুটি একটি স্ট্রিং "true"
27+
alert(typeof value); // স্ট্রিং
2828
*/!*
2929
```
3030

31-
String conversion is mostly obvious. A `false` becomes `"false"`, `null` becomes `"null"`, etc.
31+
প্রায় সব স্ট্রিং রুপান্তর সুস্পষ্ট। এখানে, `false` হয়ে যায় `"false"`, `null` হয়ে যায় `"null"`, ইত্যাদি।
3232

33-
## Numeric Conversion
33+
## সংখ্যা রূপান্তর
3434

35-
Numeric conversion happens in mathematical functions and expressions automatically.
35+
গানিতিক ফাংশন এবং এক্সপ্রেশনের ক্ষেত্রে সংখ্যায় রুপান্তর নিজে থেকেই হয়ে থাকে।
3636

37-
For example, when division `/` is applied to non-numbers:
37+
যেমন, ভাগের `/` সময় দুটি স্ট্রিং:
3838

3939
```js run
40-
alert( "6" / "2" ); // 3, strings are converted to numbers
40+
alert( "6" / "2" ); // 3, স্ট্রিংয়ের সংখ্যায় বদলে যাওয়া
4141
```
4242

43-
We can use the `Number(value)` function to explicitly convert a `value` to a number:
43+
আমরা `Number(value)` ব্যাবহার করেও স্পষ্ট করে `value` কে সংখ্যায় রূপান্তর করতে পারি:
4444

4545
```js run
4646
let str = "123";
47-
alert(typeof str); // string
47+
alert(typeof str); // স্ট্রিং
4848

49-
let num = Number(str); // becomes a number 123
49+
let num = Number(str); // সংখ্যায় 123 হয়ে গেছে
5050

51-
alert(typeof num); // number
51+
alert(typeof num); // সংখ্যা
5252
```
5353

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+
স্পট করে এই রুপান্তরের পন্থাটি তখনই কাজে লাগে, যখন এমন কোন সোর্স থেকে ভ্যালু পাই, যা স্ট্রিং দেয় অথচ যেটাকে কোন সংখ্যায় দেয়ার কথা, যেমন ঃ টেক্সট ফর্ম ।
5555

56-
If the string is not a valid number, the result of such a conversion is `NaN`. For instance:
56+
যদি স্টীং কোন ভ্যালিড সংখ্যা না হয়, তবে তা `NaN` হয়ে যায়। যথা:
5757

5858
```js run
5959
let age = Number("an arbitrary string instead of a number");
6060

61-
alert(age); // NaN, conversion failed
61+
alert(age); // NaN, রূপান্তর হয়নি
6262
```
6363

64-
Numeric conversion rules:
64+
সংখ্যা রুপান্তরের নিয়ম:
6565

66-
| Value | Becomes... |
66+
| ভ্যালু | পরিবর্তিত রুপ... |
6767
|-------|-------------|
6868
|`undefined`|`NaN`|
6969
|`null`|`0`|
70-
|<code>true&nbsp;and&nbsp;false</code> | `1` and `0` |
71-
| `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&nbsp;&nbsp;false</code> | `1` `0` |
71+
| `string` | স্ট্রিংয়ের শুরু ও শেষের স্পেস থেকে তা মুছে ফেলা হয়। বাকিটা ফাঁকা স্ট্রিং হলে, তা `0` হবে। নাহয় নাম্বারগুলি স্ট্রিং থেকে নেয়া হয়। এরর হলে `NaN` আসে। |
7272

7373
Examples:
7474

7575
```js run
7676
alert( Number(" 123 ") ); // 123
77-
alert( Number("123z") ); // NaN (error reading a number at "z")
77+
alert( Number("123z") ); // NaN ("z" এর সংখ্যা রুপান্তরে এরর)
7878
alert( Number(true) ); // 1
7979
alert( Number(false) ); // 0
8080
```
8181

82-
Please note that `null` and `undefined` behave differently here: `null` becomes zero while `undefined` becomes `NaN`.
82+
এখানে জেনে রাখি `null` `undefined` এক্ষেত্রে ভিন্ন আচরণ করে: `null` হয়ে যাবে শূন্য আর `undefined` হবে `NaN`.
8383

84-
````smart header="Addition '+' concatenates strings"
85-
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.
84+
````smart header="যোগ '+' স্ট্রিংসমূহকে একীভুত করে"
85+
প্রায় সব গানিতিক অপারেটর ভ্যালুকে সংখ্যায় রূপান্তর করে নেয়। তবে উল্লেখযোগ্য একটি ব্যতিক্রম হলো যোগ `+`, যদি এর দুপাশের একটি ভ্যালুও স্ট্রিং হয় তবে অপরটিও স্ট্রিং হয়ে যাবে
8686
87-
Then, it concatenates (joins) them:
87+
তখন এটি স্ট্রিংগুলাকে যুক্ত করে ফেলে:
8888
8989
```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' (বামপাশে স্ট্রিং)
9292
```
9393
94-
This only happens when at least one of the arguments is a string. Otherwise, values are converted to numbers.
94+
এটা তখনই হয় যদি অন্তত একটি আর্গুমেন্ট স্ট্রিং থাকে, নাহয় তা সংখ্যায় রুপান্তরিত হয়ে যাবে।
9595
````
9696

97-
## Boolean Conversion
97+
## বুলিয়ান রূপান্তর
9898

99-
Boolean conversion is the simplest one.
99+
বুলিয়ানের রূপান্তর সবচেয়ে সহজতম।
100100

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)`.
102102

103-
The conversion rule:
103+
রূপান্তর নীতি:
104104

105-
- Values that are intuitively "empty", like `0`, an empty string, `null`, `undefined`, and `NaN`, become `false`.
106-
- Other values become `true`.
105+
- ফাঁকা ভ্যালু, যেমনঃ `0`, ফাঁকা স্ট্রিং, `null`, `undefined`, `NaN`, হবে `false`.
106+
- অন্যসব হয়ে যায় `true`.
107107

108-
For instance:
108+
এক্ষেত্রে:
109109

110110
```js run
111111
alert( Boolean(1) ); // true
@@ -116,44 +116,44 @@ alert( Boolean("") ); // false
116116
```
117117

118118
````warn header="Please note: the string with zero `\"0\"` is `true`"
119-
Some languages (namely PHP) treat `"0"` as `false`. But in JavaScript, a non-empty string is always `true`.
119+
কিছু প্রোগ্রামিং ভাষায় (PHP) তে `"0"` কে `false` ধরে, কিন্তু জাভাস্ক্রিপ্ট, স্ট্রিং ফাঁকা না হলে `true` ধরে নেয়।
120120

121121
```js run
122122
alert( Boolean("0") ); // true
123-
alert( Boolean(" ") ); // spaces, also true (any non-empty string is true)
123+
alert( Boolean(" ") ); // স্পেস, এটাও true (স্ট্রিং ফাঁকা না হলেই true)
124124
```
125125
````
126126
127-
## Summary
127+
## সারসংক্ষেপ
128128
129-
The three most widely used type conversions are to string, to number, and to boolean.
129+
বহুল ব্যাবহৃত ৩টি রূপান্তরসমূহ হচ্ছে স্ট্রিং ,সংখ্যায় এবং বুলিয়ানে রুপান্তর।
130130
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)` দিয়ে করা যায়। প্রায় সব মৌলিক ভ্যালুর জন্য এটা খুব স্পষ্ট।
132132
133-
**`Numeric Conversion`** -- Occurs in math operations. Can be performed with `Number(value)`.
133+
**`সংখ্যায় রূপান্তর`** -- গানিতিক অপারেশনে হয়। `Number(value)` দিয়েও করতে পারি।
134134
135-
The conversion follows the rules:
135+
রূপান্তর নীতি:
136136
137-
| Value | Becomes... |
137+
| ভ্যালু | বদলে যায়... |
138138
|-------|-------------|
139139
|`undefined`|`NaN`|
140140
|`null`|`0`|
141141
|<code>true&nbsp;/&nbsp;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` আসে। |
143143
144-
**`Boolean Conversion`** -- Occurs in logical operations. Can be performed with `Boolean(value)`.
144+
**`বুলিয়ানে রূপান্তর`** -- লজিকাল অপারেশনে হয়। আবার `Boolean(value)` দিয়েও করা যায।
145145
146146
Follows the rules:
147147
148-
| Value | Becomes... |
148+
| ভ্যালু | বদলে যায়... |
149149
|-------|-------------|
150150
|`0`, `null`, `undefined`, `NaN`, `""` |`false`|
151-
|any other value| `true` |
151+
|অন্য যেকোন ভ্যালু| `true` |
152152
153153
154-
Most of these rules are easy to understand and memorize. The notable exceptions where people usually make mistakes are:
154+
প্রায় সব নীতিই বুঝা অ মনে রাখা সোজা। তবে কিছু কমন ভুল হলো:
155155
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
158158
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

Comments
 (0)