Pretty straightforward question. For example, are these equivalent?
window.open('http://someurl.com')
window.open('http://someurl.com', undefined)
Part of me suspects that it might depend on the function itself, but I'm not sure.
In short: In the vast majority of cases, passing undefined
is equivalent to leaving the argument out.
However, within a function, you can differentiate between an omitted argument and one that was passed as undefined
. While I would never recommend using that distinction to change behavior, you can see the difference between the two if you access the special arguments
variable within your function:
function logNumArgs() { console.log(arguments.length) } logNumArgs() // 0 logNumArgs(undefined, undefined) // 2
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.