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
The built-in`eval`function allows to execute a string of code.
3
+
বিল্ট-ইন`eval`ফাংশন স্ট্রিংকে কোড হিসেবে রানের সুবিধা প্রদান করে।
4
4
5
-
The syntax is:
5
+
এর সিনট্যাক্স হল:
6
6
7
7
```js
8
8
let result =eval(code);
9
9
```
10
10
11
-
For example:
11
+
যেমন:
12
12
13
13
```js run
14
14
let code ='alert("Hello")';
15
15
eval(code); // Hello
16
16
```
17
17
18
-
A string of code may be long, contain line breaks, function declarations, variables and so on.
18
+
একটি স্ট্রিংয়ে অনেক কোড যেমন লাইন ব্রেক ফাংশন, ভ্যারিয়েবল ডিক্লেয়ারেশন ইত্যাদি থাকতে পারে।
19
19
20
-
The result of `eval`is the result of the last statement.
20
+
`eval`এর ফলাফল হবে সর্বশেষ স্টেটমেন্টের ফলাফল।
21
21
22
-
For example:
22
+
যেমন:
23
23
```js run
24
24
let value =eval('1+1');
25
25
alert(value); // 2
@@ -30,7 +30,7 @@ let value = eval('let i = 0; ++i');
30
30
alert(value); // 1
31
31
```
32
32
33
-
The eval'ed code is executed in the current lexical environment, so it can see outer variables:
33
+
eval কোড এক্সিকিউশন লেক্সিকাল এনভায়রনমেন্টের কোডকে এক্সিকিউট করে, সুতরাং এটি এর বাইরের ভ্যারিয়েবলকে দেখতে পারে:
34
34
35
35
```js run no-beautify
36
36
let a =1;
@@ -46,15 +46,15 @@ function f() {
46
46
f();
47
47
```
48
48
49
-
It can change outer variables as well:
49
+
এটি আউটার ভ্যারিয়েবলের মান পরিবর্তনও করতে পারে:
50
50
51
51
```js untrusted refresh run
52
52
let x =5;
53
53
eval("x = 10");
54
54
alert(x); // 10, value modified
55
55
```
56
56
57
-
In strict mode, `eval`has its own lexical environment. So functions and variables, declared inside eval, are not visible outside:
57
+
`strict` মোডে, `eval`এর নিজস্ব লেক্সিকাল এনভায়রনমেন্ট থাকে। সুতরাং eval এর কোডকে এর বাইরে থেকে অ্যাক্সেস করা যাবে না:
58
58
59
59
```js untrusted refresh run
60
60
// reminder: 'use strict' is enabled in runnable examples by default
@@ -65,27 +65,27 @@ alert(typeof x); // undefined (no such variable)
65
65
// function f is also not visible
66
66
```
67
67
68
-
Without `use strict`, `eval`doesn't have its own lexical environment, so we would see `x`and`f`outside.
68
+
`use strict` ছাড়া, `eval`এর নিজস্ব লেক্সিকাল এনভায়রনমেন্ট থাকে না, সুতরাং `x`এবং`f`কে বাহির থেকে অ্যাক্সেস করতে পারব।
69
69
70
-
## Using "eval"
70
+
## "eval" এর ব্যবহার
71
71
72
-
In modern programming `eval`is used very sparingly. It's often said that "eval is evil".
72
+
মডার্ন জাভাস্ক্রিপ্টে `eval`তেমন ব্যবহার করা হয় না। এটি সম্পর্কে বলা হয় "eval is evil"।
73
73
74
-
The reason is simple: long, long time ago JavaScript was a much weaker language, many things could only be done with`eval`. But that time passed a decade ago.
74
+
প্রায় এক দশক আগে জাভাস্ক্রিপ্ট একটি দুর্বল প্রোগ্রামিং ল্যাঙ্গুয়েজ ছিল, সে সময় বিভিন্ন কাজ করতে আমরা `eval` ব্যবহার করতাম।
75
75
76
-
Right now, there's almost no reason to use `eval`. If someone is using it, there's a good chance they can replace it with a modern language construct or a [JavaScript Module](info:modules).
76
+
এখন, `eval` ব্যবহারের কোন কারণ নেই। এর পরিবর্তে আমরা মডার্ন ল্যাঙ্গুয়েজ কন্সট্রাক্ট বা [JavaScript Module](info:modules) ব্যবহার করি।
77
77
78
-
Please note that its ability to access outer variables has side-effects.
78
+
দয়া করে মনে রাখুন আউটার ভ্যারিয়েবল অ্যাক্সেস থাকার কারণে বিভিন্ন সমস্যা হতে পারে।
79
79
80
-
Code minifiers (tools used before JS gets to production, to compress it) rename local variables into shorter ones (like`a`, `b` etc) to make the code smaller. That's usually safe, but not if `eval`is used, as local variables may be accessed from eval'ed code string. So minifiers don't do that renaming for all variables potentially visible from `eval`. That negatively affects code compression ratio.
80
+
প্রোডাকশনের জন্য আমরা কোড মিনিফাই করার সময় এরা লোকাল ভ্যারিয়েবলগুলোকে শর্ট ভ্যারিয়েবল দ্বারা প্রতিস্থাপন করে (যেমন `userData` হয়ে যাবে`a`) যাতে আমাদের কোডের সাইজ ছোট হয়। এটি সুবিধাজনক, কিন্তু `eval`যেহেতু তার আউটার স্কোপকে অ্যাক্সেস করতে পারে, `eval` ব্যবহারের সময় লোকাল ভ্যারিয়েবলকে শর্ট ভ্যারিয়েবল প্রতিস্থাপন করে না। যার ফলে মিনিফাই করার সময় ফাইল সাইজের অনুপাতে একটি পার্থক্য দেখা যায়।
81
81
82
-
Using outer local variables inside `eval`is also considered a bad programming practice, as it makes maintaining the code more difficult.
82
+
এছাড়াও `eval`এ আউটার স্কোপ ভ্যারিয়েবল ব্যবহার ব্যাড প্রাক্টিস, এছাড়াও কোড সহজে পরিবর্তনযোগ্য থাকে না।
83
83
84
-
There are two ways how to be totally safe from such problems.
**যদি এটি আউটার স্কোপের ভ্যারিয়েবল ব্যবহার না করে, তাহলে `eval`এর পরিবর্তে `window.eval(...)` ব্যবহার করুন:**
87
87
88
-
This way the code is executed in the global scope:
88
+
তাহলে আমাদের কোডটি সর্বদা গ্লোবাল স্কোপে এক্সিকিউট হবে:
89
89
90
90
```js untrusted refresh run
91
91
let x =1;
@@ -95,20 +95,20 @@ let x = 1;
95
95
}
96
96
```
97
97
98
-
**If eval'ed code needs local variables, change`eval`to `new Function`and pass them as arguments:**
98
+
**যদি লোকাল ভ্যারিয়েবল অ্যাক্সেস করা লাগে, তাহলে`eval`এর পরিবর্তে `new Function`এ ভ্যালুটি পাস করার মাধ্যমে ব্যবহার করুন:**
99
99
100
100
```js run
101
101
let f =newFunction('a', 'alert(a)');
102
102
103
103
f(5); // 5
104
104
```
105
105
106
-
The `new Function`construct is explained in the chapter<info:new-function>. It creates a function from a string, also in the global scope. So it can't see local variables. But it's so much clearer to pass them explicitly as arguments, like in the example above.
106
+
`new Function`সম্পর্কে এই অধ্যায়ে আলোচনা করা হয়েছে<info:new-function>। এটি গ্লোবাল স্কোপে স্ট্রিং হতে ফাংশন তৈরি করে, তাই লোকাল ভ্যারিয়েবলকে অ্যাক্সেস করতে পারে না। সুতরাং উপরের উদাহরণের মত আর্গুমেন্ট পাসের মাধ্যমে ভ্যারিয়েবলকে অ্যাক্সেস করতে পারি।
107
107
108
-
## Summary
108
+
## সারাংশ
109
109
110
-
A call to `eval(code)`runs the string of code and returns the result of the last statement.
111
-
-Rarely used in modern JavaScript, as there's usually no need.
112
-
-Can access outer local variables. That's considered bad practice.
113
-
-Instead, to `eval`the code in the global scope, use `window.eval(code)`.
114
-
-Or, if your code needs some data from the outer scope, use `new Function`and pass it as arguments.
110
+
`eval(code)`কোন একটি স্ট্রিংয়ের কোডকে এক্সিকিউট করে এবং শেষের স্টেটমেন্টের রেজাল্ট রিটার্ন করে।
111
+
-মডার্ন জাভাস্ক্রিপ্টে বলতে গেলে এটি আর ব্যবহার করা হয় না
112
+
-আউটার স্কোপে অ্যাক্সেস থাকে, তবে এটিকে ব্যাড প্রাক্টিস হিসেবে বিবেচনা করা হয়
113
+
-গ্লোবাল স্কোপের জন্য `eval`এর পরিবর্তে `window.eval(...)` ব্যবহার করি।
114
+
-অথবা লোকাল ভ্যারিয়েবল অ্যাক্সেস এর জন্য `eval` এর পরিবর্তে `new Function`এ ভ্যালু পাস করার মাধ্যমে ব্যবহার করি।
0 commit comments