## JavaScript Code ## this is some JS code ```javascript let salute = (age) => { let showAge = (name) => { console.log(`Welcome ${name}`) console.log(`Your age is ${age}`) } return showAge } s = salute(16) // returns showAge function s("chidi") console.log(s) // returns the showAge function (name) => { console.log("Welcome " + name) console.log("Your age is " + age) } ``` ## Output Welcome chidi Your age is 16 ## Python Code ```python def salute(age): def show_age(name): print("Welcome ", name) print("Your age is ", age) return show_age # Call the function s = salute(16) # returns the show_age function s("chidi") # pass the my name argument to the show_age function ``` ## Output Welcome chidi Your age is 16
Last active
February 8, 2026 23:49
-
-
Save chidimo/430378eff15b5e1f0290bc3a8d1ce5a6 to your computer and use it in GitHub Desktop.
Comparison of Higher Order Functions (HOF) in JS and Python
let salute = (age) => {
let showAge = (name) => {
console.log(`Welcome ${name}`)
console.log(`Your age is ${age}`)
}
return showAge
}
s = salute(16) // returns showAge function
s("chidi")
console.log(s) // returns the showAge function
(name) => {
console.log("Welcome " + name)
console.log("Your age is " + age)
}Welcome chidi
Your age is 16
def salute(age):
def show_age(name):
print("Welcome ", name)
print("Your age is ", age)
return show_age
# Call the function
s = salute(16) # returns the show_age function
s("chidi") # pass the my name argument to the show_age functionWelcome chidi
Your age is 16
let salute = (age) => {
let showAge = (name) => {
console.log(`Welcome ${name}`)
console.log(`Your age is ${age}`)
}
return showAge
}
s = salute(16) // returns showAge function
s("chidi")
console.log(s) // returns the showAge function
(name) => {
console.log("Welcome " + name)
console.log("Your age is " + age)
}Welcome chidi
Your age is 16
def salute(age):
def show_age(name):
print("Welcome ", name)
print("Your age is ", age)
return show_age
# Call the function
s = salute(16) # returns the show_age function
s("chidi") # pass the my name argument to the show_age functionWelcome chidi
Your age is 16
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment