Which approach is most recommended. First or Second ?
var x = document.querySelectorAll("span");
// #1: Console returns false
x.length > 0 && x[0].blur();
// #2: Console returns undefined
if (x.length > 0) {
x[0].blur();
}
If you find x.length > 0
then you will definitely get x[0]
and do not need to check && x[0].blur();
. So your second approach is much better.
if (x.length > 0) {
x[0].blur();
}
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.