Here's a query that might appear basic and straightforward. It could even be a repeated question, as I struggled to use the correct keywords in my search.
The puzzle seems to lie in why this code snippet functions correctly:
let rAMessage = 'Ride along, everyone!'
let messageNum = 5
function computeNumber() {
return 5+5
}
function RideAlong(message, number = computeNumber()) {
alert(`${message} + ${number}`)
}
RideAlong(rAMessage)
However, this alternate version doesn't produce the desired outcome:
let rAMessage = 'Ride along, everyone!'
let messageNum = 5
function RideAlong(message, number = computeNumber()) {
function computeNumber() {
return 5+5
}
alert(`${message} + ${number}`)
}
RideAlong(rAMessage)
Is there a possible solution to make it functional?