String.prototype.valueOf()
Baseline Widely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.
시도해보기
const stringObj = new String("foo");
console.log(stringObj);
// Expected output: String { "foo" }
console.log(stringObj.valueOf());
// Expected output: "foo"
구문
js
valueOf()
매개변수
없음.
반환 값
주어진 String
객체의 원시 값을 나타내는 문자열.
설명
String
의 valueOf()
메서드는 String
객체의 원시 값을 문자열 데이터 타입으로 반환 합니다. 이 값은 String.prototype.toString()
.과 동일합니다.
이 메서드는 보통 JavaScript에 의해 내부적으로 호출되며, 코드에서 명시적으로 사용하지는 않습니다.
예제
valueOf()
사용하기
js
const x = new String("Hello world");
console.log(x.valueOf()); // 'Hello world'
명세서
Specification |
---|
ECMAScript® 2025 Language Specification # sec-string.prototype.valueof |
브라우저 호환성
BCD tables only load in the browser