new String【コンストラクタ】
String【型変換】
new String【コンストラクタ】
メモ
概要
- String【文字列】オブジェクトを生成
- new なし:String【型変換】
外部リンク
- ECMA-262 (英語)
new String ( [ value ] )
The String ConstructorES2024 (15) ES2023 (14) ES2022 (13)
構文
new String( [value] )
String【文字列】オブジェクト
value初期値
例
let str = new String(123);
console.log(typeof str); // 出力:object
console.log(str); // 出力:String {'123'}
str = new String("text");
console.log(typeof str); // 出力:object
console.log(str); // 出力:String {'text'}
str = new String("テキスト");
console.log(typeof str); // 出力:object
console.log(str); // 出力:String {'テキスト'}
String【型変換】
メモ
概要
- String型に型変換
- new あり:new String【コンストラクタ】
外部リンク
- ECMA-262 (英語)
String ( [ value ] )
String ( value )ES2024 (15) ES2023 (14) ES2022 (13)
構文
String( [value] )
String( value )
文字列 (String型)
value変換値
例
let str = String(123);
console.log(typeof str); // 出力:string
console.log(str); // 出力:123
str = String("text");
console.log(typeof str); // 出力:string
console.log(str); // 出力:text
str = String("テキスト");
console.log(typeof str); // 出力:string
console.log(str); // 出力:テキスト