'Assign parameters to existing variable [closed]
In JS how can I use this pattern but implement with something less redundant?
let apple
const myFun = (theApple, orange) => {
apple = theApple
//various stuff with apple and orange
//(apple now avail to rest of script)
}
ie- immediately apply an incoming parameter to an existing variable (which was defined in a scope above)
just inventing syntax here but something like the following would be less redundant:
let apple
const myFun = (^apple, orange) => {
//(apple is now assigned and avail
//to rest of script)
}
but if there are any real solutions/workarounds I would be interested to know.
Solution 1:[1]
let apple
const myFun = (theApple, orange) => {
apple = theApple
//various stuff with apple and orange
//(apple avail to rest of script)
}
myFun(theAppleValue, orangeValue)
console.log(apple)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Ingenious_Hans |
