Split() method need help

this is code

function reverseString(str){
let strSplit = str.split(" ")

reverseString("hello world")
console.log(reverseString());
console.log(strSplit);
}

console.log displays nothing, it should display [“hello”, “world”]

You have created an infinite recursive function: it will keep calling itself without ever reaching an end.

Are you sure you didn’t meant to close the function after split? Like

function reverseString(str){
let strSplit = str.split(" ")
} // <-- close the function body
reverseString("hello world")
console.log(reverseString());
console.log(strSplit);

Hope this helps :smile:

i tried like that, than it says: cannot read the properties of undefined(reading ‘split’)

That’s because you are trying to split an undefined value.
If you look here you are calling without any value

function reverseString(str){
let strSplit = str.split(" ")
} 
reverseString("hello world") // Does have a value
console.log(reverseString()); // <-- no value passed. Will throw error
console.log(strSplit); // <-- undefined I supposed. No `strSplit` here.