+ 7
Where does the "n" come from ?
Here's the code: ('b' + 'a' + + 'a' + 'a').toLowerCase() The output: "banana"
22 ответов
+ 20
I think 'characters' can be represented numerically with ASCII chart ( a = 65, b = 66)
It's not missing a n, it's missing "NaN" which stands for NotANumber
JavaScript couldn't convert the empty char so it prints out NaN.
Without the .toLowerCase method, the output would be
baNaNa
+ 12
Due to the "+ +a" there two things happening with 'a'. The plus sign that is closest to 'a' is acting like a unary plus operator and is trying to convert 'a' to a number if it can but since 'a' is not a number NaN is returned, which considered a number. The second plus sign will concatenate the NaN with the previous string.
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Arithmetic_Operators
https://code.sololearn.com/WyZf46u5I92t/#js
+ 4
But in single quotes it should be threated as string and not as variable and should print undefined or throw an error
update: HNNX your right its threated as number
+ 4
Ярослав Вернигора (Yaroslav Vernigora)
I found someone tweeted it on twitter with a caption " JavaScript is weird " 😂 ...so i took the code and ran it in the console and it actually printed out " banana "
+ 3
var x;
x= ('b' + 'a' + + 'a' + 'a').toLowerCase();
console.log(x);
+ 2
ODLNT Thank you sooo much , i got it 💜💙
+ 1
ODLNT thank you very much for your efforts! I got it!
+ 1
Read tutorial most carefully 😁
+ 1
I really stumbled only here:
+ +a
+ 1
You are welcome, I'm glad I could contribute to the discussion.
+ 1
Ярослав Вернигора (Yaroslav Vernigora) it's a bad explanation sorry, - ODLNT explained it better
+ 1
Heomhkl
+ 1
Thanks for sharing.
0
This shouldnt work. Please send your code to show us
0
Marina from where you get this exersises?
0
HNNX 🐿 you were right, but I didn't understand anything from your explanation. can you explain it any other way?
0
On the end its just weird
0
Bro, you are amazing !
🤣🤣😂😂
Great discovery !!!
0
Salut
0
thanks for the help