var keyword
var introduces a new variable in the current scope. It is Bnlang's only variable-declaration keyword — there is no let or const.
The Bangla form চলক is exactly equivalent.
Syntax
var <name> = <expression>;
var <name>; // declared, value is null
Examples
var greeting = "Hello";
var count = 0;
var items = [1, 2, 3];
var user = { name: "Alice" };
// Without an initializer, the variable is null.
var pending;
print(pending); // null
The Bangla form parses identically:
চলক অভিবাদন = "হ্যালো";
চলক গণনা = 0;
print(অভিবাদন, গণনা); // হ্যালো 0
Reassignment
Variables are mutable. Assign with =:
var x = 1;
x = x + 1;
print(x); // 2
There are no compound assignment operators (+=, -=, etc.). Write the full form: x = x + 1.
Scope
var declarations are scoped to the block they appear in (a { ... } body). Lookups walk outward to the enclosing function, then to the module top level.
var outer = "module";
function demo() {
var outer = "function"; // shadows the module-level outer
if (true) {
var outer = "block"; // shadows the function-level outer
print(outer); // "block"
}
print(outer); // "function"
}
demo();
print(outer); // "module"
Closures
Inner functions capture outer variables by reference — mutating them is visible from the closure:
function make_counter() {
var n = 0;
return function () {
n = n + 1;
return n;
};
}
var c = make_counter();
print(c()); // 1
print(c()); // 2
print(c()); // 3
What's not here
- No
letorconst. Usevarfor everything. If you want to communicate "this should not change," use naming conventions (UPPER_CASEconstants are a common convention). - No destructuring. Each
vardeclares exactly one name. To extract fields, dovar x = obj.x; var y = obj.y;. - No multi-declare.
var a, b, c;is not supported — use one statement per variable.