'How do i get my truncate function to not give error

//This is the function

function truncate(str, n) { return str?.length > n ? str.substr(0, n - 1) + "..." : str; };

i have tried to remove the ? from str?.length, but it only gives more errors and i keep getting "You may need an appropriate loader to handle this file type."



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source