Last active
August 9, 2023 12:30
-
-
Save scr2em/a5994c7b7c872eb6c6c65a9457d917cb to your computer and use it in GitHub Desktop.
JS Lab 3 - ASAT 2023
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function outer() { | |
var a = 10; | |
function inner() { | |
console.log(a); | |
} | |
return inner; | |
} | |
const x = outer(); | |
x(); // ? | |
// --------------------------------------- | |
function multiplyBy(x) { | |
return function (y) { | |
return x * y; | |
}; | |
} | |
const double = multiplyBy(2); | |
console.log(double(5)); // ? | |
// --------------------------------------- | |
function outer() { | |
var count = 0; | |
return function() { | |
count++; | |
return count; | |
}; | |
} | |
const increment = outer(); | |
console.log(increment() + increment()); // ? | |
// --------------------------------------- | |
function buildMessage(message) { | |
return function (name) { | |
return `${message}, ${name}!`; | |
}; | |
} | |
const greet = buildMessage("Hello"); | |
console.log(greet("Alice")); // ? | |
// --------------------------------------- | |
var funcs = []; | |
for (var i = 0; i < 3; i++) { | |
funcs.push(function() { | |
console.log(i); | |
}); | |
} | |
funcs[2](); // ? | |
// --------------------------------------- | |
function outer() { | |
var a = 5; | |
function inner() { | |
a++; | |
console.log(a); | |
} | |
return inner; | |
} | |
const incrementA = outer(); | |
incrementA(); // ? | |
incrementA(); // ? | |
// --------------------------------------- | |
function countdown(n) { | |
return function () { | |
console.log(n); | |
n--; | |
}; | |
} | |
const counter = countdown(3); | |
counter(); // ? | |
counter(); // ? | |
// --------------------------------------- | |
var number = 10; | |
function outer() { | |
var number = 5; | |
return function() { | |
console.log(number); | |
}; | |
} | |
const display = outer(); | |
display(); // ? | |
// --------------------------------------- | |
function makeCounter(start, step) { | |
var count = start; | |
return function () { | |
var current = count; | |
count += step; | |
return current; | |
}; | |
} | |
const counter = makeCounter(1, 2); | |
console.log(counter() + counter()); // ? | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment