Skip to content

Commit d955d71

Browse files
committed
back to master
1 parent 552a59e commit d955d71

File tree

1 file changed

+50
-50
lines changed

1 file changed

+50
-50
lines changed
Lines changed: 50 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
11

2-
# পুরাতন "var"
2+
# The old "var"
33

4-
অধ্যায়ের প্রথম দিকে আমরা উল্লেখ করেছিলাম [variables](info:variables) কে তিন ভাবে ঘোষণা করা যায়।
4+
In the very first chapter about [variables](info:variables), we mentioned three ways of variable declaration:
55

6-
১। `let`
7-
২। `const`
8-
৩। `var`
6+
1. `let`
7+
2. `const`
8+
3. `var`
99

10-
লেক্সিকাল এনভায়রনমেন্টের ক্ষেত্রে `let` এবং `const` ঠিক একইভাবে আচরণ করে।
10+
`let` and `const` behave exactly the same way in terms of Lexical Environments.
1111

12-
কিন্তু `var` সম্পূর্ণ ভিন্ন, যা খুব পুরানো কাল থেকেই উদ্ভূত হয়েছিল। এটি সাধারণত আধুনিক স্ক্রিপ্টগুলিতে ব্যবহৃত হয় না তবে এটি পুরানো স্ক্রিপ্টগুলিতে সচরাচর দেখা যাবে।
12+
But `var` is a very different beast, that originates from very old times. It's generally not used in modern scripts, but still lurks in the old ones.
1313

14-
আপনি যদি এই জাতীয় স্ক্রিপ্টগুলি সম্পর্কে জানার পরিকল্পনা না করেন তবে আপনি এই অধ্যায়টি এড়িয়ে যেতে পারেন, তবে তা আপনাকে পরে সমস্যায় ফেলতে পারে।
14+
If you don't plan on meeting such scripts you may even skip this chapter or postpone it, but then there's a chance that it bites you later.
1515

16-
প্রথমদিকে দেখতে var ও let এর আচরণ একই রকম মনে হবে। সেটা হলো একটি ভেরিয়েবল ঘোষণা করাঃ
16+
From the first sight, `var` behaves similar to `let`. That is, declares a variable:
1717

1818
```js run
1919
function sayHi() {
20-
var phrase = "Hello"; // লোকাল ভেরিয়েবল, "let" এর পরিবর্তে "var"
20+
var phrase = "Hello"; // local variable, "var" instead of "let"
2121

2222
alert(phrase); // Hello
2323
}
@@ -27,74 +27,74 @@ sayHi();
2727
alert(phrase); // Error, phrase is not defined
2828
```
2929

30-
...তবে এখানে পার্থক্য রয়েছে।
30+
...But here are the differences.
3131

32-
# "var" এর কোন ব্লকস্কোপ নেই।
32+
## "var" has no block scope
3333

34-
যে সকল ভেরিয়েবল "var" দ্বারা ঘোষণা হয়, তারা হয় ফাংশন-ওয়াইড অথবা গ্লোবাল হয়ে থাকে।
34+
Variables, declared with `var`, are either function-wide or global. They are visible through blocks.
3535

36-
এই ক্ষেত্রেঃ
36+
For instance:
3737

3838
```js run
3939
if (true) {
40-
var test = true; // "let" এর পরিবর্তে "var"
40+
var test = true; // use "var" instead of "let"
4141
}
4242

4343
*!*
44-
alert(test); // true, "if" ব্লকের বাইরেও এটি বিদ্যমান।
44+
alert(test); // true, the variable lives after if
4545
*/!*
4646
```
4747

48-
`var` কোড ব্লকগুলিকে উপেক্ষা করার সাথে সাথে আমরা একটি গ্লোবাল `test` ভেরিয়েবল পেয়েছি.
48+
As `var` ignores code blocks, we've got a global variable `test`.
4949

50-
যদি আমরা `var test` এর পরিবর্তে `let test` ব্যবহার করি, তবে ভেরিয়েবলটি কেবল `if` ব্লকের মধ্যে সীমাবদ্ধ থাকবেঃ
50+
If we used `let test` instead of `var test`, then the variable would only be visible inside `if`:
5151

5252
```js run
5353
if (true) {
54-
let test = true; // "let" এর ব্যবহার
54+
let test = true; // use "let"
5555
}
5656

5757
*!*
58-
alert(test); // এরর: test নির্ধারণ করা নেই
58+
alert(test); // Error: test is not defined
5959
*/!*
6060
```
6161

62-
লুপের ক্ষেত্রেও একই রকমঃ `var` লুপ অথবা ব্লকের লোকাল হতে পারে নাঃ
62+
The same thing for loops: `var` cannot be block- or loop-local:
6363

6464
```js
6565
for (var i = 0; i < 10; i++) {
6666
// ...
6767
}
6868

6969
*!*
70-
alert(i); // 10, "i" লুপের পরেও বিদ্যমান, এটি একটি গ্লোবাল ভেরিয়েবল।
70+
alert(i); // 10, "i" is visible after loop, it's a global variable
7171
*/!*
7272
```
7373

74-
যদি কোন কোড ব্লক ফাংশনের ভিতরে থাকে, সেক্ষেত্রে `var` ফাংশন লেভেল ভেরিয়েবল হয়ে যায়।
74+
If a code block is inside a function, then `var` becomes a function-level variable:
7575

7676
```js run
7777
function sayHi() {
7878
if (true) {
7979
var phrase = "Hello";
8080
}
8181

82-
alert(phrase); // কাজ করবে
82+
alert(phrase); // works
8383
}
8484

8585
sayHi();
86-
alert(phrase); // এরর: phrase নির্ধারণ করা নেই (ডেভলপার কনসোল চেক করুন)
86+
alert(phrase); // Error: phrase is not defined (Check the Developer Console)
8787
```
8888

89-
আমারা যেটা দেখলাম, `var` - `if`, `for` অথবা অন্য ব্লক ভেদ করে বাইরে আসতে পারে। তার কারন অনেক আগে জাভাস্ক্রিপ্টে কোন লেক্সিকাল এনভাইরমেন্ট ছিল না। এবং `var` তারই একটি অংশ।
89+
As we can see, `var` pierces through `if`, `for` or other code blocks. That's because a long time ago in JavaScript blocks had no Lexical Environments. And `var` is a remnant of that.
9090

91-
## "var" ফাংশনের শুরুতেই ঘোষিত হয়।
91+
## "var" declarations are processed at the function start
9292

93-
ফাংশনের শুরুতেই `var` ঘোষিত হয়ে যায়(অথবা স্ক্রিপ্ট গ্লোবালের জন্য শুরু হয়)
93+
`var` declarations are processed when the function starts (or script starts for globals).
9494

95-
অন্যভাবে বলা যায়, `var` ভেরিয়্যবল গুলো ফাংশনের শুরুতেই ঘোষিত হয়, সেটাকে যেখানেই সংজ্ঞায়িত করা হোক না কেন(ধরে নিলাম এটি কোন নেস্টেড ফাংশনের মধ্যে নয়)।
95+
In other words, `var` variables are defined from the beginning of the function, no matter where the definition is (assuming that the definition is not in the nested function).
9696

97-
তাহলেঃ
97+
So this code:
9898

9999
```js run
100100
function sayHi() {
@@ -109,7 +109,7 @@ function sayHi() {
109109
sayHi();
110110
```
111111

112-
...টেকনিক্যালি এটির মতোই(`var phrase` উপরে স্থানান্তরিত করে দেয়)ঃ
112+
...Is technically the same as this (moved `var phrase` above):
113113

114114
```js run
115115
function sayHi() {
@@ -124,7 +124,7 @@ function sayHi() {
124124
sayHi();
125125
```
126126

127-
...অথবা এটির মতো(কোড ব্লকগুলি উপেক্ষা করা হয়েছে)
127+
...Or even as this (remember, code blocks are ignored):
128128

129129
```js run
130130
function sayHi() {
@@ -141,13 +141,13 @@ function sayHi() {
141141
sayHi();
142142
```
143143

144-
লোকেরা এ জাতীয় আচরণকে "hoisting" নামেও অভিহিত করে, কারণ সমস্ত var ফাংশনের শীর্ষে "hoisting" হয়।
144+
People also call such behavior "hoisting" (raising), because all `var` are "hoisted" (raised) to the top of the function.
145145

146-
সুতরাং উপরের উদাহরণে, `if(false)` কখনও কার্যকর হয় না, কিন্তু এতে কোন সমস্যা নেই। ফাংশনের শুরুতে এর অভ্যন্তরের `var` প্রসেস হয়ে যায়, সুতরং `(*)` মুহূর্তে ভেরিয়েবলটি বিদ্যমান থাকে।
146+
So in the example above, `if (false)` branch never executes, but that doesn't matter. The `var` inside it is processed in the beginning of the function, so at the moment of `(*)` the variable exists.
147147

148-
**ডিকলারেশন গুলো "hoisted" হলেও, কিন্তু "assignment" হয় না**
148+
**Declarations are hoisted, but assignments are not.**
149149

150-
একটি উদাহরণ দিয়ে দিয়ে দেখা যাক, যেমনঃ
150+
That's better to demonstrate with an example, like this:
151151

152152
```js run
153153
function sayHi() {
@@ -161,40 +161,40 @@ function sayHi() {
161161
sayHi();
162162
```
163163

164-
`var phrase` = "Hello" লাইনটির মধ্যে দুটি কাজ রয়েছেঃ
164+
The line `var phrase = "Hello"` has two actions in it:
165165

166-
১। ভেরিয়েবল ঘোষণা `var`
167-
২। ভেরিয়াবল আসাইনমেন্ট `=`
166+
1. Variable declaration `var`
167+
2. Variable assignment `=`.
168168

169-
ফাংশন এক্সিকিউশনের শুরুতেই ডিক্লেয়ার করা হয়ে থাকে ("hoisted"),তবে অ্যাসাইনমেন্টটি সর্বদা যেখানে প্রদর্শিত হবে সেখানে কাজ করে। সুতরাং কোডটি মূলত এই ভাবে কাজ করে:
169+
The declaration is processed at the start of function execution ("hoisted"), but the assignment always works at the place where it appears. So the code works essentially like this:
170170

171171
```js run
172172
function sayHi() {
173173
*!*
174-
var phrase; // ভেরিয়েবল ডিক্লেয়ার শুরুতেই কাজ করে ...
174+
var phrase; // declaration works at the start...
175175
*/!*
176176

177177
alert(phrase); // undefined
178178

179179
*!*
180-
phrase = "Hello"; // ...অ্যাসাইনমেন্ট - যখন এক্সিকিউশন এখানে পৌঁছায়।
180+
phrase = "Hello"; // ...assignment - when the execution reaches it.
181181
*/!*
182182
}
183183

184184
sayHi();
185185
```
186186

187-
কারন সকল var ফাংশনের শুরুতেই ডিক্লেয়ার করা হয়, আমরা ওই ফাংশন স্কোপের যে কোন জায়গায় থেকে ভেরিয়েবল সমূহ কে ব্যবহার করতে পারি। কিন্তু অ্যাসাইনমেন্টের আগ পর্যন্ত ভেরিয়েবল গুলো আনডিফাইন অবস্থায় থাকে।
187+
Because all `var` declarations are processed at the function start, we can reference them at any place. But variables are undefined until the assignments.
188188

189-
উপরের দুটি উদাহরণে `alert` কোন এরর ছাড়াই চলে, কারন ভেরিয়েবল `phrase` বিদ্যমান রয়েছে। তবে এর মান এখনও নির্ধারিত হয়নি, সুতরাং এটি আনডিফাইন দেখায়।
189+
In both examples above `alert` runs without an error, because the variable `phrase` exists. But its value is not yet assigned, so it shows `undefined`.
190190

191-
## সারাংশ
191+
## Summary
192192

193-
এখানে দুটি প্রধান পার্থক্য রয়েছে `var` এবং `let/const` এর মধ্যেঃ
193+
There are two main differences of `var` compared to `let/const`:
194194

195-
১। `var` ভেরিয়েবলের কোন ব্লক স্কোপ নেই, এগুলি সর্বনিম্ন ফাংশন লেভেল পর্যন্ত বিদ্যমান থাকে।
196-
২। ফাংশনের শুরুতেই `var` ঘোষিত হয়ে যায়(স্ক্রিপ্ট গ্লোবালের জন্য শুরু হয়)।
195+
1. `var` variables have no block scope, they are visible minimum at the function level.
196+
2. `var` declarations are processed at function start (script start for globals).
197197

198-
গ্লোবাল অবজেক্টের সাথে সম্পর্কিত আরও একটি ছোটখাটো পার্থক্য রয়েছে, আমরা পরবর্তী অধ্যায়ে এটি আলোচনা করব।
198+
There's one more minor difference related to the global object, we'll cover that in the next chapter.
199199

200-
এই পার্থক্যগুলি `var` কে বেশিরভাগ সময় `let` এর চেয়ে খারাপ করে তোলে। ব্লক-লেভেলের ভেরিয়েবলগুলি একটি দুর্দান্ত জিনিস। এই জন্য `let` এর স্ট্যান্ডার্ড চালু হয় অনেক আগে, এবং ভেরিয়েবল ঘোষণার জন্য এখন এটি একটি প্রধান উপায় (`const` সহ)।
200+
These differences make `var` worse than `let` most of the time. Block-level variables is such a great thing. That's why `let` was introduced in the standard long ago, and is now a major way (along with `const`) to declare a variable.

0 commit comments

Comments
 (0)