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.

String 값의 valueOf() 메서드는 String 이 문자열 값을 반환합니다.

시도해보기

const stringObj = new String("foo");

console.log(stringObj);
// Expected output: String { "foo" }

console.log(stringObj.valueOf());
// Expected output: "foo"

구문

js
valueOf()

매개변수

없음.

반환 값

주어진 String 객체의 원시 값을 나타내는 문자열.

설명

StringvalueOf() 메서드는 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

브라우저 호환성

Report problems with this compatibility data on GitHub
desktopmobileserver
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
Deno
Node.js
valueOf

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support

같이 보기