Why does this equal ā€œHeyā€ | Sololearn: Learn to code for FREE!
Novo curso! Todo programador deveria aprender IA generativa!
Experimente uma aula grƔtis
+ 1

Why does this equal ā€œHeyā€

let a = (obj = (str) => str.split())(ā€œheyā€); console.log(a[0]); I researched split(). It is this use of a function that has my head spinning. Help me Obiwan @Brains

10th Oct 2019, 2:58 PM
Josue Cedeno
Josue Cedeno - avatar
1 Resposta
+ 1
what it basicly do is create a function with parameter str, and the function is returning str.split() the function is named obj. then executed immediately, with "hey" passed as the parameter. and as noted from mdn -IfĀ separatorĀ is omitted or doesĀ not occur inĀ str, the array returned contains one element consisting of the entire string ( https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/split )- the split will return the entire string and will return again (from function obj) to variable a.
10th Oct 2019, 5:39 PM
Taste
Taste - avatar