From ef5604506eabdc5583eb3517e2d325d7802bc1db Mon Sep 17 00:00:00 2001 From: Ashique Imran Date: Wed, 16 Oct 2019 02:35:52 +0600 Subject: [PATCH 1/3] type conversions : article.md translated --- .../06-type-conversions/article.md | 116 +++++++++--------- 1 file changed, 58 insertions(+), 58 deletions(-) diff --git a/1-js/02-first-steps/06-type-conversions/article.md b/1-js/02-first-steps/06-type-conversions/article.md index 20d093ea4..a3a350524 100644 --- a/1-js/02-first-steps/06-type-conversions/article.md +++ b/1-js/02-first-steps/06-type-conversions/article.md @@ -1,111 +1,111 @@ -# Type Conversions +# টাইপ রূপান্তর -Most of the time, operators and functions automatically convert the values given to them to the right type. +বেশীরভাগ সময়, অপারেটর ও ফাংশন সমুহ নিজে থেকেই তাদের কাছে দেয়া ভ্যালুগুলো রূপান্তর করে থাকে। -For example, `alert` automatically converts any value to a string to show it. Mathematical operations convert values to numbers. +উদাহারণ হিসাবে , `alert` নিজে থেকেই ভ্যালুকে রূপান্তর করে স্টিংয়ে রূপান্তর করে নেয়। গানিতিক অপারেটরগুলি ভ্যালুকে সংখ্যায় রূপান্তর করে। -There are also cases when we need to explicitly convert a value to the expected type. +যদিও কিছু কিছু ক্ষেত্রে আমাদেরকেই ভ্যালুকে নিজেদের মত করে রূপান্তর করে নিতে হয়। ```smart header="Not talking about objects yet" -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 . +এই অধ্যায়ে, আমরা অবজেক্ট নয় বরং, মৌলিক বিষয়গূলো জানবো। পরবর্তিতে, অবজেক্টের ধারণা পেলে, আমরা অবজেক্ট রূপান্তর নিয়ে আলোচনা করবো। . ``` -## String Conversion +## স্টিং রূপান্তর -String conversion happens when we need the string form of a value. +কোন ভ্যালু থেকে স্টিং দরকার হলে স্টিং রূপান্তর হয়। -For example, `alert(value)` does it to show the value. +উদাহরণ স্বরূপ, `alert(value)` এইকাজটি করে ভ্যালুটিকে দেখাতে। -We can also call the `String(value)` function to convert a value to a string: +আমরা একে `String(value)` ফাংশন থেকেও করতে পারি: ```js run let value = true; -alert(typeof value); // boolean +alert(typeof value); // বুলিয়ান *!* -value = String(value); // now value is a string "true" -alert(typeof value); // string +value = String(value); // এখন ভ্যালুটি একটি স্টিং "true" +alert(typeof value); // স্টিং */!* ``` -String conversion is mostly obvious. A `false` becomes `"false"`, `null` becomes `"null"`, etc. +স্টিং রুপান্তর প্রায়শই স্পষ্ট, `false` হয়ে যায় `"false"`, `null` হয়ে যায় `"null"`, etc. -## Numeric Conversion +## সংখ্যা রূপান্তর -Numeric conversion happens in mathematical functions and expressions automatically. +গানিতিক ফাংশন এবং এক্সপ্রেশনের ক্ষেত্রে সংখ্যায় রুপান্তর নিজে থেকেই হয়ে থাকে। -For example, when division `/` is applied to non-numbers: +যেমন, ভাগের `/` সময় দুটি স্টিং: ```js run -alert( "6" / "2" ); // 3, strings are converted to numbers +alert( "6" / "2" ); // 3, স্টিংয়ের সংখ্যায় বদলে যাওয়া ``` -We can use the `Number(value)` function to explicitly convert a `value` to a number: +আমরা `Number(value)` ব্যাবহার করেও স্পষ্ট করে `value` কে সংখ্যায় রূপান্তর করতে পারি: ```js run let str = "123"; -alert(typeof str); // string +alert(typeof str); // স্টিং -let num = Number(str); // becomes a number 123 +let num = Number(str); // সংখ্যায় 123 হয়ে গেছে -alert(typeof num); // number +alert(typeof num); // সংখ্যা ``` -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. +স্পট করে এই রুপান্তরের পন্থাটি তখনই কাজে লাগে যখন এমন কোন সোর্স থেকে ভ্যালু পাই যা স্টিং দেয় অথচ যার কোন সংখ্যা দেয়ার কথা, যেমন ঃ টেক্সট ফর্ম । -If the string is not a valid number, the result of such a conversion is `NaN`. For instance: +যদি স্টীং কোন ভ্যালিড সংখ্যা না হয় তবে তা `NaN` হয়ে যায়। যথা: ```js run let age = Number("an arbitrary string instead of a number"); -alert(age); // NaN, conversion failed +alert(age); // NaN, রূপান্তর হয়নি ``` -Numeric conversion rules: +সংখ্যা রুপান্তরের নিয়ম: -| Value | Becomes... | +| ভ্যালু | বদলে যায়... | |-------|-------------| |`undefined`|`NaN`| |`null`|`0`| -|true and false | `1` and `0` | -| `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`. | +|true ও false | `1` ও `0` | +| `string` | স্টিংয়ের শুরু ও শেষের স্পেস থেকে তা মুছে ফেলা হয়। বাকিটা খালি স্টীং হলে, তা `0` হবে। নাহয় নাম্বারগুলি স্টিং থেকে নেয়া হয়। এরর হলে `NaN` আসে। | Examples: ```js run alert( Number(" 123 ") ); // 123 -alert( Number("123z") ); // NaN (error reading a number at "z") +alert( Number("123z") ); // NaN ("z" এর সংখ্যা রুপান্তরে এরর) alert( Number(true) ); // 1 alert( Number(false) ); // 0 ``` -Please note that `null` and `undefined` behave differently here: `null` becomes zero while `undefined` becomes `NaN`. +এখানে জেনে রাখি `null` ও `undefined` ভিন্ন আচরণ করে: `null` হয়ে যাবে শূন্য আর `undefined` হবে `NaN`. ````smart header="Addition '+' concatenates strings" -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. +প্রায় সব গানিতিক অপারেটর ভ্যালুকে সংখ্যায় রূপান্তর করে নেয়। তবে উল্লেখযোগ্য ব্যতিক্রম হলো যোগ `+`, যদি এর দুপাশের একটি ভ্যালুও স্টিং হয় তবে অপরটিও স্টিং হয়ে যাবে -Then, it concatenates (joins) them: +তখন এটি স্টিংগুলাকে যুক্ত করে ফেলে: ```js run -alert( 1 + '2' ); // '12' (string to the right) -alert( '1' + 2 ); // '12' (string to the left) +alert( 1 + '2' ); // '12' (ডানপাশে স্টিং) +alert( '1' + 2 ); // '12' (বাপাশে স্টিং) ``` -This only happens when at least one of the arguments is a string. Otherwise, values are converted to numbers. +এটা তখনই হয় যদি অন্তত একটি আর্গুমেন্ট স্টিং হবে নাহয়, তা সংখ্যায় রুপান্তরিত হয়ে যাবে। ```` -## Boolean Conversion +## বুলিয়ান রূপান্তর -Boolean conversion is the simplest one. +বুলিয়ানের রূপান্তর সবচেয়ে সহজতম। -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)`. +এটি লজিকাল এক্সপ্রেশনের ক্ষেত্রে হয় (পরবর্তিতে কণ্ডিশনাল টেস্ট সহ অন্যগুলি দেখবো) তবে এটি সুস্পট করেও রূপান্তর করা যায় `Boolean(value)`. -The conversion rule: +রূপান্তর নীতি: -- Values that are intuitively "empty", like `0`, an empty string, `null`, `undefined`, and `NaN`, become `false`. -- Other values become `true`. +- খালি ভ্যালু, যেমনঃ `0`, খালি স্টিং, `null`, `undefined`, ও `NaN`, হবে `false`. +- অন্যসব হয়ে যায় `true`. -For instance: +এক্ষেত্রে: ```js run alert( Boolean(1) ); // true @@ -116,44 +116,44 @@ alert( Boolean("") ); // false ``` ````warn header="Please note: the string with zero `\"0\"` is `true`" -Some languages (namely PHP) treat `"0"` as `false`. But in JavaScript, a non-empty string is always `true`. +কিছু প্রোগ্রামিং ভাষায় ( পি এইচ পি ) তে `"0"` কে `false` ধরে, কিন্তু জাভাস্ক্রিপ্ট, স্টিং খালি না হলে `true` ধরে নেয়। ```js run alert( Boolean("0") ); // true -alert( Boolean(" ") ); // spaces, also true (any non-empty string is true) +alert( Boolean(" ") ); // স্পেস, এটাও true (স্টিং খালি না হলেই true) ``` ```` -## Summary +## সারসংক্ষেপ -The three most widely used type conversions are to string, to number, and to boolean. +বহুল ব্যাবহৃত ৩টি রূপান্তর হচ্ছে স্টিংয়ে,সংখ্যায়, বুলিয়ানে। -**`String Conversion`** -- Occurs when we output something. Can be performed with `String(value)`. The conversion to string is usually obvious for primitive values. +**`স্টিংয়ে রূপান্তর`** -- আউটপুট দেখতে হলে হয়। অথবা `String(value)` দিয়ে করা যায়। প্রায় সব মৌলিক ভ্যালুর জন্য এটা খুব জরুরী। -**`Numeric Conversion`** -- Occurs in math operations. Can be performed with `Number(value)`. +**`সংখ্যায় রূপান্তর`** -- গানিতিক অপারেশনে হয়। `Number(value)` দিয়েও করতে পারি। -The conversion follows the rules: + রূপান্তর নীতি: -| Value | Becomes... | +| ভ্যালু | বদলে যায়... | |-------|-------------| |`undefined`|`NaN`| |`null`|`0`| |true / false | `1 / 0` | -| `string` | The string is read "as is", whitespaces from both sides are ignored. An empty string becomes `0`. An error gives `NaN`. | +| `string` | স্টিংয়ে যা তাই আসে, স্টিংয়ের শুরু ও শেষের স্পেস থেকে তা মুছে ফেলা হয়। বাকিটা খালি স্টীং হলে, তা `0` হবে। নাহয় নাম্বারগুলি স্টিং থেকে নেয়া হয়। এরর হলে `NaN` আসে। | -**`Boolean Conversion`** -- Occurs in logical operations. Can be performed with `Boolean(value)`. +**`বুলিয়ানে রূপান্তর`** -- লজিকাল অপারেশনে হয়। আবার `Boolean(value)` দিয়েও করা যায। Follows the rules: -| Value | Becomes... | +| ভ্যালু | বদলে যায়... | |-------|-------------| |`0`, `null`, `undefined`, `NaN`, `""` |`false`| -|any other value| `true` | +|অন্য যেকোন ভ্যালু| `true` | -Most of these rules are easy to understand and memorize. The notable exceptions where people usually make mistakes are: +প্রায় সব নীতিই বুঝা অ মনে রাখা সোজা। তবে কিছু কমন ভুল হলো: -- `undefined` is `NaN` as a number, not `0`. -- `"0"` and space-only strings like `" "` are true as a boolean. +- `undefined` হয় `NaN` সংখ্যা হিসাব করলে, `0` নয় +- `"0"` ও স্পেস `" "` বুলিয়ানে true -Objects aren't covered here. We'll return to them later in the chapter that is devoted exclusively to objects after we learn more basic things about JavaScript. +অবজেক্ট এখানে কভার করা হয় নি। আমরা এখানে আবার আসবো। এটা শুধুই অব্জেক্টের জন্য যখন আমরা আরো ভালো করে জাভাস্ক্রিপ্ট শিখে ফেলবো. From 396d225ccb38d7d50bf6bb303e9e499da6c320e3 Mon Sep 17 00:00:00 2001 From: Ashique Imran Date: Wed, 16 Oct 2019 23:26:29 +0600 Subject: [PATCH 2/3] task:solution translated --- .../solution.md | 14 ++++++------ .../1-primitive-conversions-questions/task.md | 6 ++--- .../06-type-conversions/article.md | 22 +++++++++---------- 3 files changed, 21 insertions(+), 21 deletions(-) diff --git a/1-js/02-first-steps/06-type-conversions/1-primitive-conversions-questions/solution.md b/1-js/02-first-steps/06-type-conversions/1-primitive-conversions-questions/solution.md index 4964a623a..0f3839ae8 100644 --- a/1-js/02-first-steps/06-type-conversions/1-primitive-conversions-questions/solution.md +++ b/1-js/02-first-steps/06-type-conversions/1-primitive-conversions-questions/solution.md @@ -17,10 +17,10 @@ undefined + 1 = NaN // (6) " \t \n" - 2 = -2 // (7) ``` -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. -2. The subtraction `-` (like most math operations) only works with numbers, it converts an empty string `""` to `0`. -3. The addition with a string appends the number `5` to the string. -4. The subtraction always converts to numbers, so it makes `" -9 "` a number `-9` (ignoring spaces around it). -5. `null` becomes `0` after the numeric conversion. -6. `undefined` becomes `NaN` after the numeric conversion. -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`. +1. কোন স্টিংয়ের সাথে যোগের ক্ষেত্রে `"" + 1` তে `1` রূপান্তর হয়ে `"" + 1 = "1"` হয়। তাই এখানে আমরা পাই `"1" + 0`, এক্ষেত্রেও একই নিয়ম প্রযোজ্য। +2. বিয়োগ `-` (প্রায় অন্যসব অপারেটরের মতই) শুধুমাত্র সংখ্যা নিয়ে কাজ করে, এটি ফাঁকা স্টিংকে শূন্য তে রূপান্তর করে নেয় `""` থেকে `0` হবে। +3. স্টিং সংযুক্তকরণ নীতি অনুসারে `5` স্টিংয়ে রূপান্তর হবে। +4. বিয়োগের সময় স্টিং সর্বদাই সংখ্যায় রূপান্তর হয়, তাই এক্ষেত্রে `" -9 "` সংখ্যা `-9` তে পরিবর্তন হয় (এখানে স্পেসগুলিকে উপেক্ষা করে ) +5. `null` হবে `0` সংখ্যায় রুপান্তরের পর। +6. `undefined` হয়ে যায় `NaN` সংখ্যায় রূপান্তর করা হলে। +7. স্পেসসমূহ বাদ দেয়া হয় সংখ্যায় রুপান্তর করলে, এখানে পুরো স্টিংটাই বিভিন্ন স্পেসে তৈরি, যেমনঃ `\t`, `\n` এবং তাদের মাঝের "রেগুলার" স্পেসসমূহ। সুতরাং এটি ফাঁকা স্টিংয়ের মতই, যা শুন্যতে `0` রুপান্তর হয়। diff --git a/1-js/02-first-steps/06-type-conversions/1-primitive-conversions-questions/task.md b/1-js/02-first-steps/06-type-conversions/1-primitive-conversions-questions/task.md index 930c71514..86a120eb7 100644 --- a/1-js/02-first-steps/06-type-conversions/1-primitive-conversions-questions/task.md +++ b/1-js/02-first-steps/06-type-conversions/1-primitive-conversions-questions/task.md @@ -2,9 +2,9 @@ importance: 5 --- -# Type conversions +# টাইপ রূপান্তর -What are results of these expressions? +এক্সপ্রেশনগুলির ফলাফল কী হবে? ```js no-beautify "" + 1 + 0 @@ -24,4 +24,4 @@ undefined + 1 " \t \n" - 2 ``` -Think well, write down and then compare with the answer. +ভালো করে ভাবুন, লিখে রাখুন এবং আমদের উত্তরের সাথে মিলিয়ে দেখুন। diff --git a/1-js/02-first-steps/06-type-conversions/article.md b/1-js/02-first-steps/06-type-conversions/article.md index a3a350524..77f8f4768 100644 --- a/1-js/02-first-steps/06-type-conversions/article.md +++ b/1-js/02-first-steps/06-type-conversions/article.md @@ -2,7 +2,7 @@ বেশীরভাগ সময়, অপারেটর ও ফাংশন সমুহ নিজে থেকেই তাদের কাছে দেয়া ভ্যালুগুলো রূপান্তর করে থাকে। -উদাহারণ হিসাবে , `alert` নিজে থেকেই ভ্যালুকে রূপান্তর করে স্টিংয়ে রূপান্তর করে নেয়। গানিতিক অপারেটরগুলি ভ্যালুকে সংখ্যায় রূপান্তর করে। +উদাহারণ হিসাবে , `alert` নিজে থেকেই ভ্যালুকে স্টিংয়ে রূপান্তর করে নেয়। অন্যদিকে, গানিতিক অপারেটরগুলি ভ্যালুকে সংখ্যায় রূপান্তর করে। যদিও কিছু কিছু ক্ষেত্রে আমাদেরকেই ভ্যালুকে নিজেদের মত করে রূপান্তর করে নিতে হয়। @@ -12,9 +12,9 @@ ## স্টিং রূপান্তর -কোন ভ্যালু থেকে স্টিং দরকার হলে স্টিং রূপান্তর হয়। +কোন ভ্যালু থেকে স্টিং দরকার হলে স্টিং রূপান্তর করা হয়। -উদাহরণ স্বরূপ, `alert(value)` এইকাজটি করে ভ্যালুটিকে দেখাতে। +উদাহরণ স্বরূপ, `alert(value)` একাজটি করে নেয় ভ্যালুটিকে দেখাতে। আমরা একে `String(value)` ফাংশন থেকেও করতে পারি: @@ -28,7 +28,7 @@ alert(typeof value); // স্টিং */!* ``` -স্টিং রুপান্তর প্রায়শই স্পষ্ট, `false` হয়ে যায় `"false"`, `null` হয়ে যায় `"null"`, etc. +প্রায় সব স্টিং রুপান্তর সুস্পষ্ট। এখানে, `false` হয়ে যায় `"false"`, `null` হয়ে যায় `"null"`, ইত্যাদি। ## সংখ্যা রূপান্তর @@ -51,9 +51,9 @@ let num = Number(str); // সংখ্যায় 123 হয়ে গেছে alert(typeof num); // সংখ্যা ``` -স্পট করে এই রুপান্তরের পন্থাটি তখনই কাজে লাগে যখন এমন কোন সোর্স থেকে ভ্যালু পাই যা স্টিং দেয় অথচ যার কোন সংখ্যা দেয়ার কথা, যেমন ঃ টেক্সট ফর্ম । +স্পট করে এই রুপান্তরের পন্থাটি তখনই কাজে লাগে, যখন এমন কোন সোর্স থেকে ভ্যালু পাই, যা স্টিং দেয় অথচ যেটাকে কোন সংখ্যায় দেয়ার কথা, যেমন ঃ টেক্সট ফর্ম । -যদি স্টীং কোন ভ্যালিড সংখ্যা না হয় তবে তা `NaN` হয়ে যায়। যথা: +যদি স্টীং কোন ভ্যালিড সংখ্যা না হয়, তবে তা `NaN` হয়ে যায়। যথা: ```js run let age = Number("an arbitrary string instead of a number"); @@ -79,10 +79,10 @@ alert( Number(true) ); // 1 alert( Number(false) ); // 0 ``` -এখানে জেনে রাখি `null` ও `undefined` ভিন্ন আচরণ করে: `null` হয়ে যাবে শূন্য আর `undefined` হবে `NaN`. +এখানে জেনে রাখি `null` ও `undefined` এক্ষেত্রে ভিন্ন আচরণ করে: `null` হয়ে যাবে শূন্য আর `undefined` হবে `NaN`. ````smart header="Addition '+' concatenates strings" -প্রায় সব গানিতিক অপারেটর ভ্যালুকে সংখ্যায় রূপান্তর করে নেয়। তবে উল্লেখযোগ্য ব্যতিক্রম হলো যোগ `+`, যদি এর দুপাশের একটি ভ্যালুও স্টিং হয় তবে অপরটিও স্টিং হয়ে যাবে +প্রায় সব গানিতিক অপারেটর ভ্যালুকে সংখ্যায় রূপান্তর করে নেয়। তবে উল্লেখযোগ্য একটি ব্যতিক্রম হলো যোগ `+`, যদি এর দুপাশের একটি ভ্যালুও স্টিং হয় তবে অপরটিও স্টিং হয়ে যাবে তখন এটি স্টিংগুলাকে যুক্ত করে ফেলে: @@ -91,7 +91,7 @@ alert( 1 + '2' ); // '12' (ডানপাশে স্টিং) alert( '1' + 2 ); // '12' (বাপাশে স্টিং) ``` -এটা তখনই হয় যদি অন্তত একটি আর্গুমেন্ট স্টিং হবে নাহয়, তা সংখ্যায় রুপান্তরিত হয়ে যাবে। +এটা তখনই হয় যদি অন্তত একটি আর্গুমেন্ট স্টিং থাকে, নাহয় তা সংখ্যায় রুপান্তরিত হয়ে যাবে। ```` ## বুলিয়ান রূপান্তর @@ -126,9 +126,9 @@ alert( Boolean(" ") ); // স্পেস, এটাও true (স্টিং ## সারসংক্ষেপ -বহুল ব্যাবহৃত ৩টি রূপান্তর হচ্ছে স্টিংয়ে,সংখ্যায়, বুলিয়ানে। +বহুল ব্যাবহৃত ৩টি রূপান্তরসমূহ হচ্ছে স্টিংয়ে,সংখ্যায়, বুলিয়ানে। -**`স্টিংয়ে রূপান্তর`** -- আউটপুট দেখতে হলে হয়। অথবা `String(value)` দিয়ে করা যায়। প্রায় সব মৌলিক ভ্যালুর জন্য এটা খুব জরুরী। +**`স্টিংয়ে রূপান্তর`** -- আউটপুট দেখতে হলে হয়। অথবা `String(value)` দিয়ে করা যায়। প্রায় সব মৌলিক ভ্যালুর জন্য এটা খুব স্পষ্ট। **`সংখ্যায় রূপান্তর`** -- গানিতিক অপারেশনে হয়। `Number(value)` দিয়েও করতে পারি। From 900f7db314134840cdc53bd45d567338e066f6fc Mon Sep 17 00:00:00 2001 From: Ashique Imran Date: Thu, 24 Oct 2019 00:16:16 +0600 Subject: [PATCH 3/3] review done --- .../solution.md | 10 ++-- .../06-type-conversions/article.md | 58 +++++++++---------- 2 files changed, 34 insertions(+), 34 deletions(-) diff --git a/1-js/02-first-steps/06-type-conversions/1-primitive-conversions-questions/solution.md b/1-js/02-first-steps/06-type-conversions/1-primitive-conversions-questions/solution.md index 0f3839ae8..5e2bb2ac9 100644 --- a/1-js/02-first-steps/06-type-conversions/1-primitive-conversions-questions/solution.md +++ b/1-js/02-first-steps/06-type-conversions/1-primitive-conversions-questions/solution.md @@ -17,10 +17,10 @@ undefined + 1 = NaN // (6) " \t \n" - 2 = -2 // (7) ``` -1. কোন স্টিংয়ের সাথে যোগের ক্ষেত্রে `"" + 1` তে `1` রূপান্তর হয়ে `"" + 1 = "1"` হয়। তাই এখানে আমরা পাই `"1" + 0`, এক্ষেত্রেও একই নিয়ম প্রযোজ্য। -2. বিয়োগ `-` (প্রায় অন্যসব অপারেটরের মতই) শুধুমাত্র সংখ্যা নিয়ে কাজ করে, এটি ফাঁকা স্টিংকে শূন্য তে রূপান্তর করে নেয় `""` থেকে `0` হবে। -3. স্টিং সংযুক্তকরণ নীতি অনুসারে `5` স্টিংয়ে রূপান্তর হবে। -4. বিয়োগের সময় স্টিং সর্বদাই সংখ্যায় রূপান্তর হয়, তাই এক্ষেত্রে `" -9 "` সংখ্যা `-9` তে পরিবর্তন হয় (এখানে স্পেসগুলিকে উপেক্ষা করে ) +1. কোন স্ট্রিংয়ের সাথে যোগের ক্ষেত্রে `"" + 1` তে `1` রূপান্তর হয়ে `"" + 1 = "1"` হয়। তাই এখানে পায় `"1" + 0`, এক্ষেত্রেও একই নিয়ম প্রযোজ্য। +2. বিয়োগ `-` (প্রায় অন্যসব অপারেটরের মতই) শুধুমাত্র সংখ্যা নিয়ে কাজ করে, এটি ফাঁকা স্ট্রিংকে শূন্য তে রূপান্তর করে নেয় `""` থেকে `0` হবে। +3. স্ট্রিং সংযুক্তকরণ নীতি অনুসারে `5` স্ট্রিংয়ে রূপান্তর হবে। +4. বিয়োগের সময় স্ট্রিং সবসময় সংখ্যায় রূপান্তর হয়, তাই এক্ষেত্রে `" -9 "` সংখ্যা `-9` তে পরিবর্তন হয় (এখানে স্পেসগুলিকে উপেক্ষা করে ) 5. `null` হবে `0` সংখ্যায় রুপান্তরের পর। 6. `undefined` হয়ে যায় `NaN` সংখ্যায় রূপান্তর করা হলে। -7. স্পেসসমূহ বাদ দেয়া হয় সংখ্যায় রুপান্তর করলে, এখানে পুরো স্টিংটাই বিভিন্ন স্পেসে তৈরি, যেমনঃ `\t`, `\n` এবং তাদের মাঝের "রেগুলার" স্পেসসমূহ। সুতরাং এটি ফাঁকা স্টিংয়ের মতই, যা শুন্যতে `0` রুপান্তর হয়। +7. স্পেসসমূহ বাদ দেয়া হয় সংখ্যায় রুপান্তর করলে, এখানে পুরো স্ট্রিংটাই বিভিন্ন স্পেসে তৈরি, যেমনঃ `\t`, `\n` এবং তাদের মাঝের "রেগুলার" স্পেসসমূহ। সুতরাং এটি ফাঁকা স্ট্রিংয়ের মতই, যা শুন্যতে (`0`) রুপান্তর হয়। diff --git a/1-js/02-first-steps/06-type-conversions/article.md b/1-js/02-first-steps/06-type-conversions/article.md index 77f8f4768..229dadb17 100644 --- a/1-js/02-first-steps/06-type-conversions/article.md +++ b/1-js/02-first-steps/06-type-conversions/article.md @@ -2,56 +2,56 @@ বেশীরভাগ সময়, অপারেটর ও ফাংশন সমুহ নিজে থেকেই তাদের কাছে দেয়া ভ্যালুগুলো রূপান্তর করে থাকে। -উদাহারণ হিসাবে , `alert` নিজে থেকেই ভ্যালুকে স্টিংয়ে রূপান্তর করে নেয়। অন্যদিকে, গানিতিক অপারেটরগুলি ভ্যালুকে সংখ্যায় রূপান্তর করে। +উদাহারণ হিসাবে , `alert` নিজে থেকেই ভ্যালুকে স্ট্রিংয়ে রূপান্তর করে নেয়। অন্যদিকে, গানিতিক অপারেটরগুলি ভ্যালুকে সংখ্যায় রূপান্তর করে। -যদিও কিছু কিছু ক্ষেত্রে আমাদেরকেই ভ্যালুকে নিজেদের মত করে রূপান্তর করে নিতে হয়। +যদিও কিছু কিছু ক্ষেত্রে আমাদেরকেই ভ্যালুগুলোকে নিজেদের মত করে রূপান্তর করে নিতে হয়। -```smart header="Not talking about objects yet" -এই অধ্যায়ে, আমরা অবজেক্ট নয় বরং, মৌলিক বিষয়গূলো জানবো। পরবর্তিতে, অবজেক্টের ধারণা পেলে, আমরা অবজেক্ট রূপান্তর নিয়ে আলোচনা করবো। . +```smart header="এখনো অবজেক্টসমূহ নিয়ে আলোচনা হয় নি" +এই অধ্যায়ে, আমরা অবজেক্ট নয় বরং, প্রিমিটিভ বিষয়গূলো জানবো। পরবর্তিতে, অবজেক্টের ধারণা পেলে, আমরা অবজেক্ট রূপান্তর নিয়ে আলোচনা করবো। . ``` -## স্টিং রূপান্তর +## স্ট্রিং রূপান্তর -কোন ভ্যালু থেকে স্টিং দরকার হলে স্টিং রূপান্তর করা হয়। +কোন ভ্যালু থেকে স্ট্রিং দরকার হলে স্ট্রিং রূপান্তর করা হয়। -উদাহরণ স্বরূপ, `alert(value)` একাজটি করে নেয় ভ্যালুটিকে দেখাতে। +উদাহরণ স্বরূপ, `alert(value)` ভ্যালুটিকে স্ট্রিংয়ে রুপান্তর করে নেয়। -আমরা একে `String(value)` ফাংশন থেকেও করতে পারি: +আমরা একে `String(value)` ফাংশন ব্যবহার করেও স্ট্রিংয়ে রুপান্তর করতে পারিঃ ```js run let value = true; alert(typeof value); // বুলিয়ান *!* -value = String(value); // এখন ভ্যালুটি একটি স্টিং "true" -alert(typeof value); // স্টিং +value = String(value); // এখন ভ্যালুটি একটি স্ট্রিং "true" +alert(typeof value); // স্ট্রিং */!* ``` -প্রায় সব স্টিং রুপান্তর সুস্পষ্ট। এখানে, `false` হয়ে যায় `"false"`, `null` হয়ে যায় `"null"`, ইত্যাদি। +প্রায় সব স্ট্রিং রুপান্তর সুস্পষ্ট। এখানে, `false` হয়ে যায় `"false"`, `null` হয়ে যায় `"null"`, ইত্যাদি। ## সংখ্যা রূপান্তর গানিতিক ফাংশন এবং এক্সপ্রেশনের ক্ষেত্রে সংখ্যায় রুপান্তর নিজে থেকেই হয়ে থাকে। -যেমন, ভাগের `/` সময় দুটি স্টিং: +যেমন, ভাগের `/` সময় দুটি স্ট্রিং: ```js run -alert( "6" / "2" ); // 3, স্টিংয়ের সংখ্যায় বদলে যাওয়া +alert( "6" / "2" ); // 3, স্ট্রিংয়ের সংখ্যায় বদলে যাওয়া ``` আমরা `Number(value)` ব্যাবহার করেও স্পষ্ট করে `value` কে সংখ্যায় রূপান্তর করতে পারি: ```js run let str = "123"; -alert(typeof str); // স্টিং +alert(typeof str); // স্ট্রিং let num = Number(str); // সংখ্যায় 123 হয়ে গেছে alert(typeof num); // সংখ্যা ``` -স্পট করে এই রুপান্তরের পন্থাটি তখনই কাজে লাগে, যখন এমন কোন সোর্স থেকে ভ্যালু পাই, যা স্টিং দেয় অথচ যেটাকে কোন সংখ্যায় দেয়ার কথা, যেমন ঃ টেক্সট ফর্ম । +স্পট করে এই রুপান্তরের পন্থাটি তখনই কাজে লাগে, যখন এমন কোন সোর্স থেকে ভ্যালু পাই, যা স্ট্রিং দেয় অথচ যেটাকে কোন সংখ্যায় দেয়ার কথা, যেমন ঃ টেক্সট ফর্ম । যদি স্টীং কোন ভ্যালিড সংখ্যা না হয়, তবে তা `NaN` হয়ে যায়। যথা: @@ -63,12 +63,12 @@ alert(age); // NaN, রূপান্তর হয়নি সংখ্যা রুপান্তরের নিয়ম: -| ভ্যালু | বদলে যায়... | +| ভ্যালু | পরিবর্তিত রুপ... | |-------|-------------| |`undefined`|`NaN`| |`null`|`0`| |true ও false | `1` ও `0` | -| `string` | স্টিংয়ের শুরু ও শেষের স্পেস থেকে তা মুছে ফেলা হয়। বাকিটা খালি স্টীং হলে, তা `0` হবে। নাহয় নাম্বারগুলি স্টিং থেকে নেয়া হয়। এরর হলে `NaN` আসে। | +| `string` | স্ট্রিংয়ের শুরু ও শেষের স্পেস থেকে তা মুছে ফেলা হয়। বাকিটা ফাঁকা স্ট্রিং হলে, তা `0` হবে। নাহয় নাম্বারগুলি স্ট্রিং থেকে নেয়া হয়। এরর হলে `NaN` আসে। | Examples: @@ -81,17 +81,17 @@ alert( Number(false) ); // 0 এখানে জেনে রাখি `null` ও `undefined` এক্ষেত্রে ভিন্ন আচরণ করে: `null` হয়ে যাবে শূন্য আর `undefined` হবে `NaN`. -````smart header="Addition '+' concatenates strings" -প্রায় সব গানিতিক অপারেটর ভ্যালুকে সংখ্যায় রূপান্তর করে নেয়। তবে উল্লেখযোগ্য একটি ব্যতিক্রম হলো যোগ `+`, যদি এর দুপাশের একটি ভ্যালুও স্টিং হয় তবে অপরটিও স্টিং হয়ে যাবে +````smart header="যোগ '+' স্ট্রিংসমূহকে একীভুত করে" +প্রায় সব গানিতিক অপারেটর ভ্যালুকে সংখ্যায় রূপান্তর করে নেয়। তবে উল্লেখযোগ্য একটি ব্যতিক্রম হলো যোগ `+`, যদি এর দুপাশের একটি ভ্যালুও স্ট্রিং হয় তবে অপরটিও স্ট্রিং হয়ে যাবে -তখন এটি স্টিংগুলাকে যুক্ত করে ফেলে: +তখন এটি স্ট্রিংগুলাকে যুক্ত করে ফেলে: ```js run -alert( 1 + '2' ); // '12' (ডানপাশে স্টিং) -alert( '1' + 2 ); // '12' (বাপাশে স্টিং) +alert( 1 + '2' ); // '12' (ডানপাশে স্ট্রিং) +alert( '1' + 2 ); // '12' (বামপাশে স্ট্রিং) ``` -এটা তখনই হয় যদি অন্তত একটি আর্গুমেন্ট স্টিং থাকে, নাহয় তা সংখ্যায় রুপান্তরিত হয়ে যাবে। +এটা তখনই হয় যদি অন্তত একটি আর্গুমেন্ট স্ট্রিং থাকে, নাহয় তা সংখ্যায় রুপান্তরিত হয়ে যাবে। ```` ## বুলিয়ান রূপান্তর @@ -102,7 +102,7 @@ alert( '1' + 2 ); // '12' (বাপাশে স্টিং) রূপান্তর নীতি: -- খালি ভ্যালু, যেমনঃ `0`, খালি স্টিং, `null`, `undefined`, ও `NaN`, হবে `false`. +- ফাঁকা ভ্যালু, যেমনঃ `0`, ফাঁকা স্ট্রিং, `null`, `undefined`, ও `NaN`, হবে `false`. - অন্যসব হয়ে যায় `true`. এক্ষেত্রে: @@ -116,19 +116,19 @@ alert( Boolean("") ); // false ``` ````warn header="Please note: the string with zero `\"0\"` is `true`" -কিছু প্রোগ্রামিং ভাষায় ( পি এইচ পি ) তে `"0"` কে `false` ধরে, কিন্তু জাভাস্ক্রিপ্ট, স্টিং খালি না হলে `true` ধরে নেয়। +কিছু প্রোগ্রামিং ভাষায় (PHP) তে `"0"` কে `false` ধরে, কিন্তু জাভাস্ক্রিপ্ট, স্ট্রিং ফাঁকা না হলে `true` ধরে নেয়। ```js run alert( Boolean("0") ); // true -alert( Boolean(" ") ); // স্পেস, এটাও true (স্টিং খালি না হলেই true) +alert( Boolean(" ") ); // স্পেস, এটাও true (স্ট্রিং ফাঁকা না হলেই true) ``` ```` ## সারসংক্ষেপ -বহুল ব্যাবহৃত ৩টি রূপান্তরসমূহ হচ্ছে স্টিংয়ে,সংখ্যায়, বুলিয়ানে। +বহুল ব্যাবহৃত ৩টি রূপান্তরসমূহ হচ্ছে স্ট্রিং ,সংখ্যায় এবং বুলিয়ানে রুপান্তর। -**`স্টিংয়ে রূপান্তর`** -- আউটপুট দেখতে হলে হয়। অথবা `String(value)` দিয়ে করা যায়। প্রায় সব মৌলিক ভ্যালুর জন্য এটা খুব স্পষ্ট। +**`স্ট্রিংয়ে রূপান্তর`** -- আউটপুট দেখতে হলে হয়। অথবা `String(value)` দিয়ে করা যায়। প্রায় সব মৌলিক ভ্যালুর জন্য এটা খুব স্পষ্ট। **`সংখ্যায় রূপান্তর`** -- গানিতিক অপারেশনে হয়। `Number(value)` দিয়েও করতে পারি। @@ -139,7 +139,7 @@ alert( Boolean(" ") ); // স্পেস, এটাও true (স্টিং |`undefined`|`NaN`| |`null`|`0`| |true / false | `1 / 0` | -| `string` | স্টিংয়ে যা তাই আসে, স্টিংয়ের শুরু ও শেষের স্পেস থেকে তা মুছে ফেলা হয়। বাকিটা খালি স্টীং হলে, তা `0` হবে। নাহয় নাম্বারগুলি স্টিং থেকে নেয়া হয়। এরর হলে `NaN` আসে। | +| `string` | স্ট্রিংয়ে যা তাই আসে, স্ট্রিংয়ের শুরু ও শেষের স্পেস থেকে তা মুছে ফেলা হয়। বাকিটা ফাঁকা স্ট্রিং হলে, তা `0` হবে। নাহয় নাম্বারগুলি স্ট্রিং থেকে নেয়া হয়। এরর হলে `NaN` আসে। | **`বুলিয়ানে রূপান্তর`** -- লজিকাল অপারেশনে হয়। আবার `Boolean(value)` দিয়েও করা যায।