Movatterモバイル変換


[0]ホーム

URL:


  1. 개발자를 위한 웹 기술
  2. JavaScript
  3. JavaScript 참고서
  4. 식 및 연산자
  5. 단항 더하기 (+)

This page was translated from English by the community.Learn more and join the MDN Web Docs community.

View in EnglishAlways switch to English

단항 더하기 (+)

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since ⁨2015년 7월⁩.

단항 더하기 연산자(+)는 피연산자 앞에 위치하며 피연산자를 평가하지만, 만약 피연산자가 숫자가 아니라면 숫자로 변환을 시도합니다.

시도해 보기

const x = 1;const y = -1;console.log(+x);// Expected output: 1console.log(+y);// Expected output: -1console.log(+"");// Expected output: 0console.log(+true);// Expected output: 1console.log(+false);// Expected output: 0console.log(+"hello");// Expected output: NaN

구문

js
+x;

설명

단항 부정 (-)도 숫자가 아닌 값을 변환할 수 있지만, 단항 더하기는어떤 것을 숫자로 변환하는 가장 빠르고 선호하는 방법입니다. 왜냐하면 숫자에 대해 다른 연산을 수행하지 않기 때문입니다.정수와 실수의 문자열 표현뿐 아니라 문자열이 아닌 값인true,falsenull 또한 변환할 수 있습니다.10진수 및 16진수(0x 접두사) 형식의 정수 모두 지원됩니다. 음수도 지원됩니다(16진수 제외).BigInt 값에 연산자를 사용하면 TypeError가 발생합니다. 특정 값을 구문 분석할 수 없으면NaN으로 평가됩니다.

예제

숫자에 사용하기

js
const x = 1;const y = -1;console.log(+x);// 1console.log(+y);// -1

숫자가 아닌 값에 사용하기

js
+true; // 1+false; // 0+null; // 0+function (val) {  return val;}; // NaN+1n; // TypeError 발생: BigInt 값을 숫자로 변경할 수 없습니다

명세

Specification
ECMAScript® 2026 Language Specification
# sec-unary-plus-operator

브라우저 호환성

같이 보기

Help improve MDN

Learn how to contribute

This page was last modified on byMDN contributors.


[8]ページ先頭

©2009-2025 Movatter.jp