Use try to wrap code that may throw an error, and catch to handle the error gracefully, preventing crashes.
try
catch
try { let result = someFunction(); } catch (error) { console.error("Error:", error); }