diff options
author | Jongha Kim <kim.jongha@gmail.com> | 2021-07-12 23:04:21 +0900 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-07-12 23:04:21 +0900 |
commit | 9358d5be7f62495bc426ddcd839e17ebdc741e6b (patch) | |
tree | 8d9986f3ce993ff4dac6dd14d84858ceb1dea869 /files/ko/web | |
parent | 44d48aa9ac2c04028485f34f1c9cd2dc4d8224cb (diff) | |
download | translated-content-9358d5be7f62495bc426ddcd839e17ebdc741e6b.tar.gz translated-content-9358d5be7f62495bc426ddcd839e17ebdc741e6b.tar.bz2 translated-content-9358d5be7f62495bc426ddcd839e17ebdc741e6b.zip |
Add unary operators (#1385)
* Add unary operators
* Update files/ko/web/javascript/reference/operators/unary_plus/index.html
Co-authored-by: hochan Lee <hochan049@gmail.com>
* Update files/ko/web/javascript/reference/operators/unary_plus/index.html
Co-authored-by: hochan Lee <hochan049@gmail.com>
* Update files/ko/web/javascript/reference/operators/unary_negation/index.html
Co-authored-by: alattalatta <urty5656@gmail.com>
* Update files/ko/web/javascript/reference/operators/unary_plus/index.html
* Update files/ko/web/javascript/reference/operators/unary_negation/index.html
Co-authored-by: hochan Lee <hochan049@gmail.com>
Co-authored-by: alattalatta <urty5656@gmail.com>
Diffstat (limited to 'files/ko/web')
-rw-r--r-- | files/ko/web/javascript/reference/operators/unary_negation/index.html | 64 | ||||
-rw-r--r-- | files/ko/web/javascript/reference/operators/unary_plus/index.html | 71 |
2 files changed, 135 insertions, 0 deletions
diff --git a/files/ko/web/javascript/reference/operators/unary_negation/index.html b/files/ko/web/javascript/reference/operators/unary_negation/index.html new file mode 100644 index 0000000000..46f8f01f48 --- /dev/null +++ b/files/ko/web/javascript/reference/operators/unary_negation/index.html @@ -0,0 +1,64 @@ +--- +title: 단항 부정 (-) +slug: Web/JavaScript/Reference/Operators/Unary_negation +tags: +- JavaScript +- Language feature +- Operator +- Reference +browser-compat: javascript.operators.unary_negation +--- +<div>{{jsSidebar("Operators")}}</div> + +<p>단항 부정 연산자(<code>-</code>)는 피연산자 앞에 위치하며, 피연산자의 부호를 부정합니다. 즉 양수는 음수로, 음수는 양수로 바꿉니다.</p> + +<div>{{EmbedInteractiveExample("pages/js/expressions-unary-negation.html")}}</div> + + +<h2 id="Syntax">구문</h2> + +<pre class="brush: js">-<var>x</var> +</pre> + +<h2 id="Examples">예제</h2> + +<h3 id="Negating_numbers">숫자 부정하기</h3> + +<pre class="brush: js">const x = 3; +const y = -x; + +// y = -3 +// x = 3 +</pre> + +<h3 id="Negating_non-numbers">숫자가 아닌 값을 부정하기</h3> + +<p>단항 부정 연산자는 숫자가 아닌 값을 숫자로 변환할 수 있습니다.</p> + +<pre class="brush: js">const x = "4"; +const y = -x; + +// y = -4 +</pre> + +<h2 id="Specifications">명세</h2> + +{{Specifications}} + +<h2 id="Browser_compatibility">브라우저 호환성</h2> + +<p>{{Compat}}</p> + +<h2 id="See_also">같이 보기</h2> + +<ul> + <li><a href="/ko/docs/Web/JavaScript/Reference/Operators/Addition">더하기 연산자</a></li> + <li><a href="/ko/docs/Web/JavaScript/Reference/Operators/Subtraction">빼기 연산자</a></li> + <li><a href="/ko/docs/Web/JavaScript/Reference/Operators/Division">나누기 연산자</a></li> + <li><a href="/ko/docs/Web/JavaScript/Reference/Operators/Multiplication">곱하기 연산자</a></li> + <li><a href="/ko/docs/Web/JavaScript/Reference/Operators/Remainder">나머지 연산자</a></li> + <li><a href="/ko/docs/Web/JavaScript/Reference/Operators/Exponentiation">지수 연산자</a></li> + <li><a href="/ko/docs/Web/JavaScript/Reference/Operators/Increment">증가 연산자</a></li> + <li><a href="/ko/docs/Web/JavaScript/Reference/Operators/Decrement">감소 연산자</a></li> + <li><a href="/ko/docs/Web/JavaScript/Reference/Operators/Unary_plus">단항 더하기 연산자</a></li> +</ul> diff --git a/files/ko/web/javascript/reference/operators/unary_plus/index.html b/files/ko/web/javascript/reference/operators/unary_plus/index.html new file mode 100644 index 0000000000..ee2edcc3be --- /dev/null +++ b/files/ko/web/javascript/reference/operators/unary_plus/index.html @@ -0,0 +1,71 @@ +--- +title: 단항 더하기 (+) +slug: Web/JavaScript/Reference/Operators/Unary_plus +tags: +- JavaScript +- Language feature +- Operator +- Reference +browser-compat: javascript.operators.unary_plus +--- +<div>{{jsSidebar("Operators")}}</div> + +<p>단항 더하기 연산자(<code>+</code>)는 피연산자 앞에 위치하며 피연산자를 평가하지만, 만약 피연산자가 숫자가 아니라면 숫자로 변환을 시도합니다.</p> + +<div>{{EmbedInteractiveExample("pages/js/expressions-unary-plus.html", "taller")}}</div> + +<h2 id="Syntax">구문</h2> + +<pre class="brush: js">+<var>x</var> +</pre> + +<h2 id="Description">설명</h2> + +<p>단항 부정 (<code>-</code>)도 숫자가 아닌 값을 변환할 수 있지만, 단항 더하기는 + 어떤 것을 숫자로 변환하는 가장 빠르고 선호하는 방법입니다. 왜냐하면 숫자에 대해 다른 연산을 수행하지 않기 때문입니다. + 정수와 실수의 문자열 표현뿐 아니라 문자열이 아닌 값인 <code>true</code>, <code>false</code> 및 <code>null</code> 또한 변환할 수 있습니다. + 10진수 및 16진수(<code>0x</code> 접두사) 형식의 정수 모두 지원됩니다. 음수도 지원됩니다(16진수 제외). + BigInt 값에 연산자를 사용하면 TypeError가 발생합니다. 특정 값을 구문 분석할 수 없으면 {{jsxref("NaN")}}으로 평가됩니다.</p> + +<h2 id="Examples">예제</h2> + +<h3 id="Usage_with_numbers">숫자에 사용하기</h3> + +<pre class="brush: js">const x = 1; +const y = -1; + +console.log(+x); +// 1 +console.log(+y); +// -1</pre> + +<h3 id="Usage_with_non-numbers">숫자가 아닌 값에 사용하기</h3> + +<pre class="brush: js">+true // 1 ++false // 0 ++null // 0 ++function(val){ return val } // NaN ++1n // TypeError 발생: BigInt 값을 숫자로 변경할 수 없습니다 +</pre> + +<h2 id="Specifications">명세</h2> + +{{Specifications}} + +<h2 id="Browser_compatibility">브라우저 호환성</h2> + +<p>{{Compat}}</p> + +<h2 id="See_also">같이 보기</h2> + +<ul> + <li><a href="/ko/docs/Web/JavaScript/Reference/Operators/Addition">더하기 연산자</a></li> + <li><a href="/ko/docs/Web/JavaScript/Reference/Operators/Subtraction">빼기 연산자</a></li> + <li><a href="/ko/docs/Web/JavaScript/Reference/Operators/Division">나누기 연산자</a></li> + <li><a href="/ko/docs/Web/JavaScript/Reference/Operators/Multiplication">곱하기 연산자</a></li> + <li><a href="/ko/docs/Web/JavaScript/Reference/Operators/Remainder">나머지 연산자</a></li> + <li><a href="/ko/docs/Web/JavaScript/Reference/Operators/Exponentiation">지수 연산자</a></li> + <li><a href="/ko/docs/Web/JavaScript/Reference/Operators/Increment">증가 연산자</a></li> + <li><a href="/ko/docs/Web/JavaScript/Reference/Operators/Decrement">감소 연산자</a></li> + <li><a href="/ko/docs/Web/JavaScript/Reference/Operators/Unary_negation">단항 부정 연산자</a></li> +</ul> |