-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
33 lines (26 loc) · 693 Bytes
/
index.js
File metadata and controls
33 lines (26 loc) · 693 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
function outerFunction() {
let outerVariable = 'I am outside!';
function innerFunction() {
console.log(outerVariable); // دسترسی به متغیر بیرونی
}
return innerFunction;
}
const myFunction = outerFunction();
myFunction(); // 'I am outside!'
function createCounter() {
let count = 0;
return {
increment: function() {
count++;
return count;
},
reset: function() {
count = 0;
return count;
}
};
}
const counter = createCounter();
console.log(counter.increment()); // 1
console.log(counter.increment()); // 2
console.log(counter.reset()); // 0