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
In the very first chapter about[variables](info:variables), we mentioned three ways of variable declaration:
4
+
অধ্যায়ের প্রথম দিকে আমরা উল্লেখ করেছিলাম[variables](info:variables) কে তিন ভাবে ঘোষণা করা যায়।
5
5
6
-
1.`let`
7
-
2.`const`
8
-
3.`var`
6
+
১।`let`
7
+
২।`const`
8
+
৩।`var`
9
9
10
-
`let`and`const`behave exactly the same way in terms of Lexical Environments.
10
+
লেক্সিকাল এনভায়রনমেন্টের ক্ষেত্রে `let`এবং`const`ঠিক একইভাবে আচরণ করে।
11
11
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.
12
+
কিন্তু`var`সম্পূর্ণ ভিন্ন, যা খুব পুরানো কাল থেকেই উদ্ভূত হয়েছিল। এটি সাধারণত আধুনিক স্ক্রিপ্টগুলিতে ব্যবহৃত হয় না তবে এটি পুরানো স্ক্রিপ্টগুলিতে সচরাচর দেখা যাবে।
13
13
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.
14
+
আপনি যদি এই জাতীয় স্ক্রিপ্টগুলি সম্পর্কে জানার পরিকল্পনা না করেন তবে আপনি এই অধ্যায়টি এড়িয়ে যেতে পারেন, তবে তা আপনাকে পরে সমস্যায় ফেলতে পারে।
15
15
16
-
From the first sight, `var` behaves similar to `let`. That is, declares a variable:
16
+
প্রথমদিকে দেখতে var ও let এর আচরণ একই রকম মনে হবে। সেটা হলো একটি ভেরিয়েবল ঘোষণা করাঃ
17
17
18
18
```js run
19
19
functionsayHi() {
20
-
var phrase ="Hello"; //local variable, "var" instead of "let"
20
+
var phrase ="Hello"; //লোকাল ভেরিয়েবল, "let" এর পরিবর্তে "var"
21
21
22
22
alert(phrase); // Hello
23
23
}
@@ -27,74 +27,74 @@ sayHi();
27
27
alert(phrase); // Error, phrase is not defined
28
28
```
29
29
30
-
...But here are the differences.
30
+
...তবে এখানে পার্থক্য রয়েছে।
31
31
32
-
##"var" has no block scope
32
+
# "var" এর কোন ব্লক স্কোপ নেই।
33
33
34
-
Variables, declared with `var`, are either function-wide or global. They are visible through blocks.
34
+
যে সকল ভেরিয়েবল "var" দ্বারা ঘোষণা হয়, তারা হয় ফাংশন-ওয়াইড অথবা গ্লোবাল হয়ে থাকে।
35
35
36
-
For instance:
36
+
এই ক্ষেত্রেঃ
37
37
38
38
```js run
39
39
if (true) {
40
-
var test =true; //use "var" instead of "let"
40
+
var test =true; //"let" এর পরিবর্তে "var"
41
41
}
42
42
43
43
*!*
44
-
alert(test); // true, the variable lives after if
44
+
alert(test); // true, "if" ব্লকের বাইরেও এটি বিদ্যমান।
45
45
*/!*
46
46
```
47
47
48
-
As `var`ignores code blocks, we've got a global variable `test`.
48
+
`var`কোড ব্লকগুলিকে উপেক্ষা করার সাথে সাথে আমরা একটি গ্লোবাল `test` ভেরিয়েবল পেয়েছি.
49
49
50
-
If we used `let test`instead of `var test`, then the variable would only be visible inside `if`:
50
+
যদি আমরা `var test`এর পরিবর্তে `let test` ব্যবহার করি, তবে ভেরিয়েবলটি কেবল `if` ব্লকের মধ্যে সীমাবদ্ধ থাকবেঃ
51
51
52
52
```js run
53
53
if (true) {
54
-
let test =true; //use "let"
54
+
let test =true; // "let" এর ব্যবহার
55
55
}
56
56
57
57
*!*
58
-
alert(test); //Error: test is not defined
58
+
alert(test); //এরর: test নির্ধারণ করা নেই
59
59
*/!*
60
60
```
61
61
62
-
The same thing for loops:`var`cannot be block- or loop-local:
62
+
লুপের ক্ষেত্রেও একই রকমঃ `var`লুপ অথবা ব্লকের লোকাল হতে পারে নাঃ
63
63
64
64
```js
65
65
for (var i =0; i <10; i++) {
66
66
// ...
67
67
}
68
68
69
69
*!*
70
-
alert(i); // 10, "i" is visible after loop, it's a global variable
70
+
alert(i); // 10, "i" লুপের পরেও বিদ্যমান, এটি একটি গ্লোবাল ভেরিয়েবল।
71
71
*/!*
72
72
```
73
73
74
-
If a code block is inside a function, then`var`becomes a function-level variable:
74
+
যদি কোন কোড ব্লক ফাংশনের ভিতরে থাকে, সেক্ষেত্রে`var`ফাংশন লেভেল ভেরিয়েবল হয়ে যায়।
75
75
76
76
```js run
77
77
functionsayHi() {
78
78
if (true) {
79
79
var phrase ="Hello";
80
80
}
81
81
82
-
alert(phrase); //works
82
+
alert(phrase); //কাজ করবে
83
83
}
84
84
85
85
sayHi();
86
-
alert(phrase); //Error: phrase is not defined (Check the Developer Console)
86
+
alert(phrase); //এরর: phrase নির্ধারণ করা নেই (ডেভলপার কনসোল চেক করুন)
87
87
```
88
88
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.
89
+
আমারা যেটা দেখলাম, `var`- `if`, `for`অথবা অন্য ব্লক ভেদ করে বাইরে আসতে পারে। তার কারন অনেক আগে জাভাস্ক্রিপ্টে কোন লেক্সিকাল এনভাইরমেন্ট ছিল না। এবং `var`তারই একটি অংশ।
90
90
91
-
## "var" declarations are processed at the function start
91
+
## "var" ফাংশনের শুরুতেই ঘোষিত হয়।
92
92
93
-
`var`declarations are processed when the function starts (or script starts for globals).
93
+
ফাংশনের শুরুতেই `var`ঘোষিত হয়ে যায়(অথবা স্ক্রিপ্ট গ্লোবালের জন্য শুরু হয়)
94
94
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).
95
+
অন্যভাবে বলা যায়, `var`ভেরিয়্যবল গুলো ফাংশনের শুরুতেই ঘোষিত হয়, সেটাকে যেখানেই সংজ্ঞায়িত করা হোক না কেন(ধরে নিলাম এটি কোন নেস্টেড ফাংশনের মধ্যে নয়)।
96
96
97
-
So this code:
97
+
তাহলেঃ
98
98
99
99
```js run
100
100
functionsayHi() {
@@ -109,7 +109,7 @@ function sayHi() {
109
109
sayHi();
110
110
```
111
111
112
-
...Is technically the same as this (moved `var phrase`above):
112
+
...টেকনিক্যালি এটির মতোই(`var phrase`উপরে স্থানান্তরিত করে দেয়)ঃ
113
113
114
114
```js run
115
115
functionsayHi() {
@@ -124,7 +124,7 @@ function sayHi() {
124
124
sayHi();
125
125
```
126
126
127
-
...Or even as this (remember, code blocks are ignored):
127
+
...অথবা এটির মতো(কোড ব্লকগুলি উপেক্ষা করা হয়েছে)
128
128
129
129
```js run
130
130
functionsayHi() {
@@ -141,13 +141,13 @@ function sayHi() {
141
141
sayHi();
142
142
```
143
143
144
-
People also call such behavior "hoisting" (raising), because all `var` are "hoisted" (raised) to the top of the function.
144
+
লোকেরা এ জাতীয় আচরণকে "hoisting" নামেও অভিহিত করে, কারণ সমস্ত var ফাংশনের শীর্ষে "hoisting" হয়।
145
145
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.
146
+
সুতরাং উপরের উদাহরণে, `if(false)`কখনও কার্যকর হয় না, কিন্তু এতে কোন সমস্যা নেই। ফাংশনের শুরুতে এর অভ্যন্তরের `var` প্রসেস হয়ে যায়, সুতরং `(*)`মুহূর্তে ভেরিয়েবলটি বিদ্যমান থাকে।
147
147
148
-
**Declarations are hoisted, but assignments are not.**
148
+
**ডিকলারেশন গুলো "hoisted" হলেও, কিন্তু "assignment" হয় না**
149
149
150
-
That's better to demonstrate with an example, like this:
150
+
একটি উদাহরণ দিয়ে দিয়ে দেখা যাক, যেমনঃ
151
151
152
152
```js run
153
153
functionsayHi() {
@@ -161,40 +161,40 @@ function sayHi() {
161
161
sayHi();
162
162
```
163
163
164
-
The line `var phrase = "Hello"` has two actions in it:
164
+
`var phrase` = "Hello" লাইনটির মধ্যে দুটি কাজ রয়েছেঃ
165
165
166
-
1. Variable declaration`var`
167
-
2. Variable assignment`=`.
166
+
১। ভেরিয়েবল ঘোষণা`var`
167
+
২। ভেরিয়াবল আসাইনমেন্ট`=`।
168
168
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:
169
+
ফাংশন এক্সিকিউশনের শুরুতেই ডিক্লেয়ার করা হয়ে থাকে ("hoisted"),তবে অ্যাসাইনমেন্টটি সর্বদা যেখানে প্রদর্শিত হবে সেখানে কাজ করে। সুতরাং কোডটি মূলত এই ভাবে কাজ করে:
170
170
171
171
```js run
172
172
functionsayHi() {
173
173
*!*
174
-
var phrase; //declaration works at the start...
174
+
var phrase; //ভেরিয়েবল ডিক্লেয়ার শুরুতেই কাজ করে ...
175
175
*/!*
176
176
177
177
alert(phrase); // undefined
178
178
179
179
*!*
180
-
phrase ="Hello"; // ...assignment - when the execution reaches it.
180
+
phrase ="Hello"; // ...অ্যাসাইনমেন্ট - যখন এক্সিকিউশন এখানে পৌঁছায়।
181
181
*/!*
182
182
}
183
183
184
184
sayHi();
185
185
```
186
186
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.
187
+
কারন সকল var ফাংশনের শুরুতেই ডিক্লেয়ার করা হয়, আমরা ওই ফাংশন স্কোপের যে কোন জায়গায় থেকে ভেরিয়েবল সমূহ কে ব্যবহার করতে পারি। কিন্তু অ্যাসাইনমেন্টের আগ পর্যন্ত ভেরিয়েবল গুলো আনডিফাইন অবস্থায় থাকে।
188
188
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`.
189
+
উপরের দুটি উদাহরণে `alert`কোন এরর ছাড়াই চলে, কারন ভেরিয়েবল `phrase`বিদ্যমান রয়েছে। তবে এর মান এখনও নির্ধারিত হয়নি, সুতরাং এটি আনডিফাইন দেখায়।
190
190
191
-
## Summary
191
+
## সারাংশ
192
192
193
-
There are two main differences of `var`compared to `let/const`:
193
+
এখানে দুটি প্রধান পার্থক্য রয়েছে `var`এবং `let/const` এর মধ্যেঃ
194
194
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).
195
+
১।`var`ভেরিয়েবলের কোন ব্লক স্কোপ নেই, এগুলি সর্বনিম্ন ফাংশন লেভেল পর্যন্ত বিদ্যমান থাকে।
196
+
২। ফাংশনের শুরুতেই `var`ঘোষিত হয়ে যায়(স্ক্রিপ্ট গ্লোবালের জন্য শুরু হয়)।
197
197
198
-
There's one more minor difference related to the global object, we'll cover that in the next chapter.
198
+
গ্লোবাল অবজেক্টের সাথে সম্পর্কিত আরও একটি ছোটখাটো পার্থক্য রয়েছে, আমরা পরবর্তী অধ্যায়ে এটি আলোচনা করব।
199
199
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.
200
+
এই পার্থক্যগুলি `var`কে বেশিরভাগ সময় `let`এর চেয়ে খারাপ করে তোলে। ব্লক-লেভেলের ভেরিয়েবলগুলি একটি দুর্দান্ত জিনিস। এই জন্য `let`এর স্ট্যান্ডার্ড চালু হয় অনেক আগে, এবং ভেরিয়েবল ঘোষণার জন্য এখন এটি একটি প্রধান উপায় (`const` সহ)।
0 commit comments