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
There's another very simple and concise syntax for creating functions, that's often better than Function Expressions.
3
+
এটা ফাংশন তৈরির আরেকটা খুব সহজ এবং সংক্ষিপ্ত কিন্তু খুবই কার্যকরী একটি রূপ, প্রায়ই দেখা যায়, সাধারণ যে ফাংশন আছে তার থেকে এটা ভাল।
4
4
5
-
It's called "arrow functions", because it looks like this:
5
+
6
+
একে "এ্যারো ফাংশন" বলা হয় কারণ এটা দেখতে অনেকটা এই রকমঃ
6
7
7
8
```js
8
9
letfunc= (arg1, arg2, ...argN) => expression
9
10
```
10
11
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`টি সম্পাদন করে তার যে রেজাল্ট হয় সেটা রিটার্ন করছে।
12
13
13
-
In other words, it's the shorter version of:
14
+
অন্যথায় বলতে গেলে, এটা নিম্নোক্ত কোডটির সংক্ষিপ্ত রূপ।
14
15
15
16
```js
16
17
letfunc=function(arg1, arg2, ...argN) {
17
18
return expression;
18
19
};
19
20
```
20
21
21
-
Let's see a concrete example:
22
+
চলুন, একটা বাস্তবিক উদাহরণ দেখা যাকঃ
22
23
23
24
```js run
24
25
letsum= (a, b) => a + b;
25
26
26
-
/*This arrow function is a shorter form of:
27
+
/*এই এ্যারো ফাংশনটা নিচের কোডটির সংক্ষিপ্ত রূপঃ
27
28
28
29
let sum = function(a, b) {
29
30
return a + b;
@@ -33,79 +34,80 @@ let sum = function(a, b) {
33
34
alert( sum(1, 2) ); // 3
34
35
```
35
36
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`এক্সপ্রেশনটির মান নির্ণয় করছে এবং তার রেজাল্টটি রিটার্ন করছে।
37
38
38
-
-If we have only one argument, then parentheses around parameters can be omitted, making that even shorter.
39
+
-যদি আমাদের কেবল একটি মাত্র আর্গুমেন্ট থাকে তাহলে প্যারামিটারগুলোর দুই পাশে যে প্যারেন্থেসিস বা প্রথম বন্ধনী থাকে সেটি না দিলেও চলে, যেটা কোডটাকে আরও সংক্ষিপ্ত করে নিয়ে আসে।
39
40
40
-
For example:
41
+
উদাহরণ স্বরূপঃ
41
42
42
43
```js run
43
44
*!*
44
45
letdouble=n=> n *2;
45
-
//roughly the same as: let double = function(n) { return n * 2 }
46
+
//এটা বলেতে গেলে let double = function(n) { return n * 2 } এর একটি অন্যরূপ।
46
47
*/!*
47
48
48
49
alert( double(3) ); // 6
49
50
```
50
51
51
-
-If there are no arguments, parentheses will be empty (but they should be present):
52
+
-যদি ফাংশনের কোন আর্গুমেন্ট না থাকে তাহলে প্যারেন্থেসিস বা প্রথম বন্ধনীদ্বয় খালি থাকবে (কিন্তু তারা উপস্থিত থাকবে)
52
53
53
54
```js run
54
-
let sayHi = () => alert("Hello!");
55
+
let sayHi = () => alert("হ্যালো!");
55
56
56
57
sayHi();
57
58
```
58
59
59
-
Arrow functions can be used in the same way as Function Expressions.
60
+
এ্যারো ফাংশন, ফাংশন এক্সপ্রেশনের মত একই ভাবে ব্যবহার করা যায়।
60
61
61
-
For instance, to dynamically create a function:
62
+
এই ক্ষেত্রে, ডাইন্যামিকভাবে একটা ফাংশন তৈরি করতে গেলেঃ
62
63
63
64
```js run
64
-
let age = prompt("What is your age?", 18);
65
+
let age = prompt("আপনার বয়স কত?", 18);
65
66
66
67
let welcome = (age < 18) ?
67
-
() => alert('Hello') :
68
-
() => alert("Greetings!");
68
+
() => alert('হ্যালো') :
69
+
() => alert("অভিবাদন!");
69
70
70
71
welcome();
71
72
```
72
73
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
+
এ্যারো ফাংশন হয়ত শুরুর দিকে কিছুটা অন্য রকম এবং খুব একটা পাঠযোগ্য নাও লাগতে পারে, কিন্তু আমাদের এই মনোভাব খুব তাড়াতাড়ি বদলে যাবে যেহেতু খুব দ্রুতই আমরা এর গঠনের সাথে অভ্যস্থ হয়ে যাব।
74
75
75
-
They are very convenient for simple one-line actions, when we're just too lazy to write many words.
76
+
এটা এক লাইনের কাজের জন্য খুবই সুবিধাজনক যখন আমরা খুব বেশি একটা লিখতে চাই না।
76
77
77
-
## Multiline arrow functions
78
+
## অনেক লাইনের এ্যারো ফাংশন
78
79
79
-
The examples above took arguments from the left of `=>` and evaluated the right-side expression with them.
80
+
উপড়ের উদাহরণগুলোতে (`=>`) এই চিহ্নের বাম পাশে আর্গুমেন্ট সমূহ নিয়েছে এবং তাদের সাহায্যে ডান পাশের এক্সপ্রেশনটির মান নির্ধারন করেছে।
80
81
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`ব্যবহার করতে হবে।
82
83
83
-
Like this:
84
+
অনেকটা এইরকমঃ
84
85
85
86
```js run
86
-
let sum = (a, b) => { // the curly brace opens a multiline function
87
+
let sum = (a, b) => { // এই কার্লি ব্র্যাসটা শুরু করে একটা বহুলাইন ফাংশনের।
87
88
let result = a + b;
88
89
*!*
89
-
return result; // if we use curly braces, then we need an explicit "return"
90
+
return result; // যদি আমরা কার্লি ব্র্যাসেস ব্যবহার করি, তাহলে আমাদের আলাদাকরে একটা "return" ব্যবহার করা লাগবে।
90
91
*/!*
91
92
};
92
93
93
94
alert( sum(1, 2) ); // 3
94
95
```
95
96
96
97
```smart header="More to come"
97
-
Here we praised arrow functions for brevity. But that's not all!
98
+
এখানে আমরা এ্যারো ফাংশনের "সংক্ষিপ্ত রূপের" প্রশংসা করলাম। কিন্তু এইটাই এর সবকিছু নয়!
98
99
99
-
Arrow functions have other interesting features.
100
+
এ্যারো ফাংশনের আরও খুব মজার মজার অন্যান্য ফিচার রয়েছে।
100
101
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> এই চ্যাপ্টারে এ্যারো ফাংশন নিয়ে ফিরে আসব।
102
103
103
-
For now, we can already use arrow functions for one-line actions and callbacks.
104
+
তো এখন পর্যন্ত দেখতে গেলে, আমরা এ্যারো ফাংশন ব্যবহার করে এক লাইনের কোন কাজ এবং কলব্যাক সম্পাদন করতে পারি।
104
105
```
105
106
106
107
## Summary
108
+
## মূলকথা
107
109
108
-
Arrow functions are handy for one-liners. They come in two flavors:
110
+
এ্যারো ফাংশন এক লাইনের কাজের জন্য খুব সুবিধাজনক। এটা দুই প্রকার হতে পারেঃ
109
111
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