Skip to content

Commit bb8fd71

Browse files
author
Md. Jamal Uddin
authored
Merge pull request #56 from ahamed/arrow-function-basic
Arrow functions, the basics
2 parents 0a518fe + 7ef1eac commit bb8fd71

File tree

3 files changed

+44
-42
lines changed

3 files changed

+44
-42
lines changed

1-js/02-first-steps/16-arrow-functions-basics/1-rewrite-arrow/solution.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@ function ask(question, yes, no) {
66
}
77

88
ask(
9-
"Do you agree?",
9+
"আপনি কি রাজি?",
1010
*!*
11-
() => alert("You agreed."),
12-
() => alert("You canceled the execution.")
11+
() => alert("আপনি রাজি হয়েছেন।"),
12+
() => alert("আপনি কাজটি বাতিল করেছেন।")
1313
*/!*
1414
);
1515
```
1616

17-
Looks short and clean, right?
17+
দেখতে ছোট এবং ঝকঝকে লাগছে, তাই না?
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

2-
# Rewrite with arrow functions
2+
# এ্যারো ফাংশন দিয়ে পুনরায় লিখা
33

4-
Replace Function Expressions with arrow functions in the code below:
4+
নিচের কোডের ফাংশন এক্সপ্রেশনটি এ্যারো ফাংশন দিয়ে পরিবর্তন করুনঃ
55

66
```js run
77
function ask(question, yes, no) {
@@ -10,8 +10,8 @@ function ask(question, yes, no) {
1010
}
1111

1212
ask(
13-
"Do you agree?",
14-
function() { alert("You agreed."); },
15-
function() { alert("You canceled the execution."); }
13+
"আপনি কি রাজি?",
14+
function() { alert("আপনি রাজি হয়েছেন।"); },
15+
function() { alert("আপনি কাজটি বাতিল করেছেন।"); }
1616
);
1717
```
Lines changed: 35 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,30 @@
1-
# Arrow functions, the basics
1+
# এ্যারো ফাংশনের মূল বিষয়াবলি
22

3-
There's another very simple and concise syntax for creating functions, that's often better than Function Expressions.
3+
এটা ফাংশন তৈরির আরেকটা খুব সহজ এবং সংক্ষিপ্ত কিন্তু খুবই কার্যকরী একটি রূপ, প্রায়ই দেখা যায়, সাধারণ যে ফাংশন আছে তার থেকে এটা ভাল।
44

5-
It's called "arrow functions", because it looks like this:
5+
6+
একে "এ্যারো ফাংশন" বলা হয় কারণ এটা দেখতে অনেকটা এই রকমঃ
67

78
```js
89
let func = (arg1, arg2, ...argN) => expression
910
```
1011

11-
...This creates a function `func` that accepts arguments `arg1..argN`, then evaluates the `expression` on the right side with their use and returns its result.
12+
এখানে `func` নামে একটা ফাংশন তৈরি করা হয়েছে যা `arg1..argN` আর্গুমেন্ট হিসেবে নিচ্ছে, তারপর ডানপাশের `expression` টি সম্পাদন করে তার যে রেজাল্ট হয় সেটা রিটার্ন করছে।
1213

13-
In other words, it's the shorter version of:
14+
অন্যথায় বলতে গেলে, এটা নিম্নোক্ত কোডটির সংক্ষিপ্ত রূপ।
1415

1516
```js
1617
let func = function(arg1, arg2, ...argN) {
1718
return expression;
1819
};
1920
```
2021

21-
Let's see a concrete example:
22+
চলুন, একটা বাস্তবিক উদাহরণ দেখা যাকঃ
2223

2324
```js run
2425
let sum = (a, b) => a + b;
2526

26-
/* This arrow function is a shorter form of:
27+
/* এই এ্যারো ফাংশনটা নিচের কোডটির সংক্ষিপ্ত রূপঃ
2728
2829
let sum = function(a, b) {
2930
return a + b;
@@ -33,79 +34,80 @@ let sum = function(a, b) {
3334
alert( sum(1, 2) ); // 3
3435
```
3536

36-
As you can, see `(a, b) => a + b` means a function that accepts two arguments named `a` and `b`. Upon the execution, it evaluates the expression `a + b` and returns the result.
37+
এখানে আপনি যেমনটি দেখতে পাচ্ছেন, `(a, b) => a + b` ফাংশনটি দুইটা আর্গুমেন্ট নিচ্ছে যথাক্রমে `a` `b` এবং সম্পাদনের সময় এটি `a + b` এক্সপ্রেশনটির মান নির্ণয় করছে এবং তার রেজাল্টটি রিটার্ন করছে।
3738

38-
- If we have only one argument, then parentheses around parameters can be omitted, making that even shorter.
39+
- যদি আমাদের কেবল একটি মাত্র আর্গুমেন্ট থাকে তাহলে প্যারামিটারগুলোর দুই পাশে যে প্যারেন্থেসিস বা প্রথম বন্ধনী থাকে সেটি না দিলেও চলে, যেটা কোডটাকে আরও সংক্ষিপ্ত করে নিয়ে আসে।
3940

40-
For example:
41+
উদাহরণ স্বরূপঃ
4142

4243
```js run
4344
*!*
4445
let double = n => n * 2;
45-
// roughly the same as: let double = function(n) { return n * 2 }
46+
// এটা বলেতে গেলে let double = function(n) { return n * 2 } এর একটি অন্যরূপ।
4647
*/!*
4748

4849
alert( double(3) ); // 6
4950
```
5051

51-
- If there are no arguments, parentheses will be empty (but they should be present):
52+
- যদি ফাংশনের কোন আর্গুমেন্ট না থাকে তাহলে প্যারেন্থেসিস বা প্রথম বন্ধনীদ্বয় খালি থাকবে (কিন্তু তারা উপস্থিত থাকবে)
5253

5354
```js run
54-
let sayHi = () => alert("Hello!");
55+
let sayHi = () => alert("হ্যালো!");
5556
5657
sayHi();
5758
```
5859

59-
Arrow functions can be used in the same way as Function Expressions.
60+
এ্যারো ফাংশন, ফাংশন এক্সপ্রেশনের মত একই ভাবে ব্যবহার করা যায়।
6061

61-
For instance, to dynamically create a function:
62+
এই ক্ষেত্রে, ডাইন্যামিকভাবে একটা ফাংশন তৈরি করতে গেলেঃ
6263

6364
```js run
64-
let age = prompt("What is your age?", 18);
65+
let age = prompt("আপনার বয়স কত?", 18);
6566
6667
let welcome = (age < 18) ?
67-
() => alert('Hello') :
68-
() => alert("Greetings!");
68+
() => alert('হ্যালো') :
69+
() => alert("অভিবাদন!");
6970
7071
welcome();
7172
```
7273

73-
Arrow functions may appear unfamiliar and not very readable at first, but that quickly changes as the eyes get used to the structure.
74+
এ্যারো ফাংশন হয়ত শুরুর দিকে কিছুটা অন্য রকম এবং খুব একটা পাঠযোগ্য নাও লাগতে পারে, কিন্তু আমাদের এই মনোভাব খুব তাড়াতাড়ি বদলে যাবে যেহেতু খুব দ্রুতই আমরা এর গঠনের সাথে অভ্যস্থ হয়ে যাব।
7475

75-
They are very convenient for simple one-line actions, when we're just too lazy to write many words.
76+
এটা এক লাইনের কাজের জন্য খুবই সুবিধাজনক যখন আমরা খুব বেশি একটা লিখতে চাই না।
7677

77-
## Multiline arrow functions
78+
## অনেক লাইনের এ্যারো ফাংশন
7879

79-
The examples above took arguments from the left of `=>` and evaluated the right-side expression with them.
80+
উপড়ের উদাহরণগুলোতে (`=>`) এই চিহ্নের বাম পাশে আর্গুমেন্ট সমূহ নিয়েছে এবং তাদের সাহায্যে ডান পাশের এক্সপ্রেশনটির মান নির্ধারন করেছে।
8081

81-
Sometimes we need something a little bit more complex, like multiple expressions or statements. It is also possible, but we should enclose them in curly braces. Then use a normal `return` within them.
82+
কিন্তু কখনো সখনো আমাদের এর থেকে কিছুটা বেশি জটিল কাজ করতে হয়, যেমন একের অধিক এক্সপ্রেশন অথবা স্টেটমেন্ট সম্পাদন করা। এটাও সম্ভব, কিন্তু তার জন্য তাদের কার্লি ব্র্যাসেস বা দ্বিতীয় বন্ধনীর ভিতরে লিখতে হবে। তারপর সেখানে একটা সাধারন `return` ব্যবহার করতে হবে।
8283

83-
Like this:
84+
অনেকটা এইরকমঃ
8485

8586
```js run
86-
let sum = (a, b) => { // the curly brace opens a multiline function
87+
let sum = (a, b) => { // এই কার্লি ব্র্যাসটা শুরু করে একটা বহুলাইন ফাংশনের।
8788
let result = a + b;
8889
*!*
89-
return result; // if we use curly braces, then we need an explicit "return"
90+
return result; // যদি আমরা কার্লি ব্র্যাসেস ব্যবহার করি, তাহলে আমাদের আলাদাকরে একটা "return" ব্যবহার করা লাগবে।
9091
*/!*
9192
};
9293
9394
alert( sum(1, 2) ); // 3
9495
```
9596

9697
```smart header="More to come"
97-
Here we praised arrow functions for brevity. But that's not all!
98+
এখানে আমরা এ্যারো ফাংশনের "সংক্ষিপ্ত রূপের" প্রশংসা করলাম। কিন্তু এইটাই এর সবকিছু নয়!
9899
99-
Arrow functions have other interesting features.
100+
এ্যারো ফাংশনের আরও খুব মজার মজার অন্যান্য ফিচার রয়েছে।
100101
101-
To study them in-depth, we first need to get to know some other aspects of JavaScript, so we'll return to arrow functions later in the chapter <info:arrow-functions>.
102+
এদের আরও গভীর ভাবে জানতে হলে প্রথমে আমাদের জাভাস্ক্রিপ্টের কিছু অন্যান্য বিষয়াবলি সম্পর্কে জানতে হবে। সুতরাং পরবর্তিতে আমরা <info:arrow-functions> এই চ্যাপ্টারে এ্যারো ফাংশন নিয়ে ফিরে আসব।
102103
103-
For now, we can already use arrow functions for one-line actions and callbacks.
104+
তো এখন পর্যন্ত দেখতে গেলে, আমরা এ্যারো ফাংশন ব্যবহার করে এক লাইনের কোন কাজ এবং কলব্যাক সম্পাদন করতে পারি।
104105
```
105106

106107
## Summary
108+
## মূলকথা
107109

108-
Arrow functions are handy for one-liners. They come in two flavors:
110+
এ্যারো ফাংশন এক লাইনের কাজের জন্য খুব সুবিধাজনক। এটা দুই প্রকার হতে পারেঃ
109111

110-
1. Without curly braces: `(...args) => expression` -- the right side is an expression: the function evaluates it and returns the result.
111-
2. With curly braces: `(...args) => { body }` -- brackets allow us to write multiple statements inside the function, but we need an explicit `return` to return something.
112+
1. কোন কার্লি ব্র্যাসেস ছাড়াঃ `(...args) => expression` -- ডান পাশের অংশটা একটা এক্সপ্রেশন এবং ফাংশনটি এই এক্সপ্রেশনের মান নির্ণয় করে এবং সেটা রিটার্ন করে।
113+
2. কার্লি ব্র্যাসেস সহঃ `(...args) => { body }` -- বন্ধনীসমূহ ফাংশনের ভিতরে একের অধিক স্ট্যাটমেন্ট লিখতে দিচ্ছে, কিন্তু আমাদের কোন কিছু রিটার্ন করার জন্য আলাদা করে `return` ব্যবহার করতে হবে।

0 commit comments

Comments
 (0)