前後の空白文字(スペース・タブ・改行)を除去する
' hello '.trim(); // 'hello'
' hello '.trimStart(); // 'hello '
' hello '.trimEnd(); // ' hello'
const clean = userInput.trim();
if (clean.length === 0) throw new Error('空文字は不可');APIレスポンスやユーザー入力の文字列クリーニングによく使う。タブや改行も除去される。