+ 7

Where does the "n" come from ?

Here's the code: ('b' + 'a' + + 'a' + 'a').toLowerCase() The output: "banana"

26th Dec 2019, 6:21 PM
Marina Khamis
Marina Khamis  - avatar
22 Answers
+ 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
26th Dec 2019, 6:28 PM
HNNX 🐿
HNNX 🐿 - avatar
+ 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
26th Dec 2019, 9:09 PM
ODLNT
ODLNT - avatar
+ 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
26th Dec 2019, 6:34 PM
Nico Ruder
Nico Ruder - avatar
+ 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 "
26th Dec 2019, 8:37 PM
Marina Khamis
Marina Khamis  - avatar
+ 3
var x; x= ('b' + 'a' + + 'a' + 'a').toLowerCase(); console.log(x);
26th Dec 2019, 8:20 PM
Yaroslav Vernigora
Yaroslav Vernigora - avatar
+ 2
ODLNT Thank you sooo much , i got it 💜💙
26th Dec 2019, 9:21 PM
Marina Khamis
Marina Khamis  - avatar
+ 1
ODLNT thank you very much for your efforts! I got it!
26th Dec 2019, 9:19 PM
Yaroslav Vernigora
Yaroslav Vernigora - avatar
+ 1
Read tutorial most carefully 😁
26th Dec 2019, 9:38 PM
Yaroslav Vernigora
Yaroslav Vernigora - avatar
+ 1
I really stumbled only here: + +a
26th Dec 2019, 9:40 PM
Yaroslav Vernigora
Yaroslav Vernigora - avatar
+ 1
You are welcome, I'm glad I could contribute to the discussion.
26th Dec 2019, 9:44 PM
ODLNT
ODLNT - avatar
+ 1
Ярослав Вернигора (Yaroslav Vernigora) it's a bad explanation sorry, - ODLNT explained it better
27th Dec 2019, 10:48 AM
HNNX 🐿
HNNX 🐿 - avatar
+ 1
Heomhkl
27th Dec 2019, 12:44 PM
Alpha Bah
Alpha Bah - avatar
+ 1
Thanks for sharing.
27th Dec 2019, 2:58 PM
Rajkumar Bhaduri
Rajkumar Bhaduri - avatar
0
This shouldnt work. Please send your code to show us
26th Dec 2019, 6:25 PM
Nico Ruder
Nico Ruder - avatar
0
Marina from where you get this exersises?
26th Dec 2019, 8:26 PM
Yaroslav Vernigora
Yaroslav Vernigora - avatar
0
HNNX 🐿 you were right, but I didn't understand anything from your explanation. can you explain it any other way?
26th Dec 2019, 8:34 PM
Yaroslav Vernigora
Yaroslav Vernigora - avatar
0
On the end its just weird
26th Dec 2019, 9:36 PM
Nico Ruder
Nico Ruder - avatar
0
Bro, you are amazing ! 🤣🤣😂😂 Great discovery !!!
28th Dec 2019, 12:42 PM
Ajit Kumar
Ajit Kumar - avatar
0
Salut
28th Dec 2019, 3:42 PM
Evtimii Anisoara
0
thanks for the help
30th Dec 2019, 7:45 AM
MAD_GOD_KING
MAD_GOD_KING - avatar