I was wondering why this function returns true and false values? I wasn't expecting numbers necessarily, but am confused - is it something to do with how the forEach method works?
function canDrive(...years){ years.forEach(cur => console.log((2020 - cur) >= 21)); } canDrive(1990, 1999, 1965)
It is "returning" boolean values because there is a comparison statement inside of the console.log:
console.log((2020 - cur) >= 21)
This is converting it to a boolean. (it is actually logging, not returning as @Bergi mentioned in the comments)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.