[Solved] Cannot read property of ‘…’ undefined [closed]


In

console.log(convertToHex())

your are not passing any parameter to convertToHex, and that function expects a parameter:

function convertToHex(str)
//                    ^^^

Now when you call that function like you did without passing an argument, str inside the function will be undefined.

And thus, here:

for(var i=0; i < str.length; i++)
//                 ^^^^

undefined has no length.

solved Cannot read property of ‘…’ undefined [closed]