+ 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
1 ответ
+ 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.