A quiz about type-coercion, indexOf return values, and the principle of lol whoo...
source link: https://miketaylr.com/posts/2014/03/a-quiz.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
A quiz about type-coercion, indexOf return values, and the principle of lol whoops a bug.
03 Mar 2014
Given the following version
[method][code], and assuming a.User.device()
returns the string "android"
, what is the return value assuming navigator.userAgent
is:
Mozilla/5.0 (Android; Mobile; rv:30.0) Gecko/30.0 Firefox/30.0
?
version: function() {
agent = window.navigator.userAgent;
switch (a.User.device()) {
...
case "android":
return window.Number(agent.substr(agent.indexOf("Android ") + 8, 3));
...
}
}
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
The answer is NaN
, obviously.
[code]: https://gist.github.com/miketaylr/9333150#file-mobile-min-js-L21214-L21226da
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK