|
|
|
|
|
by jhatemyjob
1342 days ago
|
|
I don't mean to screw up the whole vibe of your comment, but... if 0 then
print('0 is true')
else
print('0 is false')
end
prints "0 is true". The reason why "you can just do `if str:find('a')`" is because it returns nil.string.find never returns 0. |
|
If you do `if (str.indexOf("a"))` in javascript; you'll miss out on the case where the string starts with "a", because the index returned 0, which is falsy.
EDIT: Oh, sorry, I see what you mean. You're right, my bad.
EDIT2: I guess, let me rephrase. 0 is rarely returned for things, so the falsiness of it doesn't usually enter into the equation. So you can do things like that, regardless of the truthiness of 0, because it's not used, whereas in other langauges, you usually have to check, unless they have 0 as truthy as well. (though I guess this isn't much of an argument in favour of 1-indexes)