Skip to content

Commit 76df5fd

Browse files
authored
Merge pull request #164 from msisaifu/eval
Eval: run a code string
2 parents 7cc2e80 + 1176b86 commit 76df5fd

File tree

1 file changed

+29
-29
lines changed

1 file changed

+29
-29
lines changed

1-js/99-js-misc/02-eval/article.md

+29-29
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,25 @@
1-
# Eval: run a code string
1+
# Eval: স্ট্রিং হতে কোড এক্সিকিউট
22

3-
The built-in `eval` function allows to execute a string of code.
3+
বিল্ট-ইন `eval` ফাংশন স্ট্রিংকে কোড হিসেবে রানের সুবিধা প্রদান করে।
44

5-
The syntax is:
5+
এর সিনট্যাক্স হল:
66

77
```js
88
let result = eval(code);
99
```
1010

11-
For example:
11+
যেমন:
1212

1313
```js run
1414
let code = 'alert("Hello")';
1515
eval(code); // Hello
1616
```
1717

18-
A string of code may be long, contain line breaks, function declarations, variables and so on.
18+
একটি স্ট্রিংয়ে অনেক কোড যেমন লাইন ব্রেক ফাংশন, ভ্যারিয়েবল ডিক্লেয়ারেশন ইত্যাদি থাকতে পারে।
1919

20-
The result of `eval` is the result of the last statement.
20+
`eval` এর ফলাফল হবে সর্বশেষ স্টেটমেন্টের ফলাফল।
2121

22-
For example:
22+
যেমন:
2323
```js run
2424
let value = eval('1+1');
2525
alert(value); // 2
@@ -30,7 +30,7 @@ let value = eval('let i = 0; ++i');
3030
alert(value); // 1
3131
```
3232

33-
The eval'ed code is executed in the current lexical environment, so it can see outer variables:
33+
eval কোড এক্সিকিউশন লেক্সিকাল এনভায়রনমেন্টের কোডকে এক্সিকিউট করে, সুতরাং এটি এর বাইরের ভ্যারিয়েবলকে দেখতে পারে:
3434

3535
```js run no-beautify
3636
let a = 1;
@@ -46,15 +46,15 @@ function f() {
4646
f();
4747
```
4848

49-
It can change outer variables as well:
49+
এটি আউটার ভ্যারিয়েবলের মান পরিবর্তনও করতে পারে:
5050

5151
```js untrusted refresh run
5252
let x = 5;
5353
eval("x = 10");
5454
alert(x); // 10, value modified
5555
```
5656

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 এর কোডকে এর বাইরে থেকে অ্যাক্সেস করা যাবে না:
5858

5959
```js untrusted refresh run
6060
// reminder: 'use strict' is enabled in runnable examples by default
@@ -65,27 +65,27 @@ alert(typeof x); // undefined (no such variable)
6565
// function f is also not visible
6666
```
6767

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` কে বাহির থেকে অ্যাক্সেস করতে পারব।
6969

70-
## Using "eval"
70+
## "eval" এর ব্যবহার
7171

72-
In modern programming `eval` is used very sparingly. It's often said that "eval is evil".
72+
মডার্ন জাভাস্ক্রিপ্টে `eval` তেমন ব্যবহার করা হয় না। এটি সম্পর্কে বলা হয় "eval is evil"
7373

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` ব্যবহার করতাম।
7575

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) ব্যবহার করি।
7777

78-
Please note that its ability to access outer variables has side-effects.
78+
দয়া করে মনে রাখুন আউটার ভ্যারিয়েবল অ্যাক্সেস থাকার কারণে বিভিন্ন সমস্যা হতে পারে।
7979

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` ব্যবহারের সময় লোকাল ভ্যারিয়েবলকে শর্ট ভ্যারিয়েবল প্রতিস্থাপন করে না। যার ফলে মিনিফাই করার সময় ফাইল সাইজের অনুপাতে একটি পার্থক্য দেখা যায়।
8181

82-
Using outer local variables inside `eval` is also considered a bad programming practice, as it makes maintaining the code more difficult.
82+
এছাড়াও `eval` এ আউটার স্কোপ ভ্যারিয়েবল ব্যবহার ব্যাড প্রাক্টিস, এছাড়াও কোড সহজে পরিবর্তনযোগ্য থাকে না।
8383

84-
There are two ways how to be totally safe from such problems.
84+
এক্ষেত্রে আমরা দুই উপায়ে এটি ব্যবহার করতে পারি।
8585

86-
**If eval'ed code doesn't use outer variables, please call `eval` as `window.eval(...)`:**
86+
**যদি এটি আউটার স্কোপের ভ্যারিয়েবল ব্যবহার না করে, তাহলে `eval` এর পরিবর্তে `window.eval(...)` ব্যবহার করুন:**
8787

88-
This way the code is executed in the global scope:
88+
তাহলে আমাদের কোডটি সর্বদা গ্লোবাল স্কোপে এক্সিকিউট হবে:
8989

9090
```js untrusted refresh run
9191
let x = 1;
@@ -95,20 +95,20 @@ let x = 1;
9595
}
9696
```
9797

98-
**If eval'ed code needs local variables, change `eval` to `new Function` and pass them as arguments:**
98+
**যদি লোকাল ভ্যারিয়েবল অ্যাক্সেস করা লাগে, তাহলে `eval` এর পরিবর্তে `new Function` এ ভ্যালুটি পাস করার মাধ্যমে ব্যবহার করুন:**
9999

100100
```js run
101101
let f = new Function('a', 'alert(a)');
102102

103103
f(5); // 5
104104
```
105105

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>। এটি গ্লোবাল স্কোপে স্ট্রিং হতে ফাংশন তৈরি করে, তাই লোকাল ভ্যারিয়েবলকে অ্যাক্সেস করতে পারে না। সুতরাং উপরের উদাহরণের মত আর্গুমেন্ট পাসের মাধ্যমে ভ্যারিয়েবলকে অ্যাক্সেস করতে পারি।
107107

108-
## Summary
108+
## সারাংশ
109109

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

Comments
 (0)