diff options
Diffstat (limited to 'files/ko/web/api/console/assert')
-rw-r--r-- | files/ko/web/api/console/assert/index.md | 99 |
1 files changed, 34 insertions, 65 deletions
diff --git a/files/ko/web/api/console/assert/index.md b/files/ko/web/api/console/assert/index.md index 3ad2aafa8e..42ddad30d0 100644 --- a/files/ko/web/api/console/assert/index.md +++ b/files/ko/web/api/console/assert/index.md @@ -1,48 +1,51 @@ --- title: console.assert() -slug: Web/API/Console/assert +slug: Web/API/console/assert tags: - API - DOM + - Debugging - Method - - Reference + - Web Development - console + - web console +browser-compat: api.console.assert translation_of: Web/API/console/assert --- -<div>{{APIRef("Console API")}}</div> +{{APIRef("Console API")}} -<p><code><strong>console.assert()</strong></code> 메서드는 주어진 가정이 거짓인 경우 콘솔에 오류 메시지를 출력합니다. 참인 경우, 아무것도 하지 않습니다.</p> +**`console.assert()`** 메서드는 주어진 가정이 거짓인 경우 콘솔에 오류 메시지를 출력합니다. 참인 경우, 아무것도 하지 않습니다. -<p>{{AvailableInWorkers}}</p> +{{AvailableInWorkers}} -<h2 id="구문">구문</h2> +## 구문 -<pre class="syntaxbox">console.assert(<em>assertion</em>, <em>obj1</em> [, <em>obj2</em>, ..., <em>objN</em>]); -console.assert(<em>assertion</em>, <em>msg</em> [, <em>subst1</em>, ..., <em>substN</em>]); // c-like message formatting -</pre> +```js +console.assert(assertion, obj1 [, obj2, ..., objN]); +console.assert(assertion, msg [, subst1, ..., substN]); // C-like message formatting +``` -<h3 id="Parameters">Parameters</h3> +### 매개변수 -<dl> - <dt><code>assertion</code></dt> - <dd>아무 불리언 표현식. 거짓인 경우, 메시지를 콘솔에 출력합니다.</dd> - <dt><code>obj1</code> ... <code>objN</code></dt> - <dd>출력에 사용할 JavaScript 객체. 각각의 문자열 표현을 순서대로 출력합니다.</dd> - <dt><code>msg</code></dt> - <dd>0개 이상의 치환 문자열을 포함하는 JavaScript 문자열.</dd> - <dt><code>subst1</code> ... <code>substN</code></dt> - <dd><code>msg</code> 매개변수의 치환 문자열에 대입할 JavaScript 객체.</dd> -</dl> +- `assertion` + - : 아무 불리언 표현식. 거짓인 경우, 메시지를 콘솔에 출력합니다. +- `obj1` ... `objN` + - : 출력에 사용할 JavaScript 객체. 각각의 문자열 표현은 입력한 순서대로 함께 출력됩니다. +- `msg` + - : 0개 이상의 치환 문자열을 포함하는 JavaScript 문자열. +- `subst1` ... `substN` + - : `msg` 매개변수의 치환 문자열에 대입할 JavaScript 객체. 이 매개변수를 사용하면 출력 형식을 추가로 제어할 수 있습니다. -<h2 id="예제">예제</h2> +## 예제 -<p>다음 예제는 객체와 가정을 함께 사용하는 법을 보입니다.</p> +다음 예제는 객체와 가정을 함께 사용하는 법을 보입니다. -<pre class="brush: js">const errorMsg = 'the # is not even'; -for (let number = 2; number <= 5; number += 1) { +```js +const errorMsg = 'the # is not even'; +for (let number = 2; number <= 5; number += 1) { console.log('the # is ' + number); console.assert(number % 2 === 0, {number: number, errorMsg: errorMsg}); - // or, using <a href="/ko/docs/Web/JavaScript/Reference/Operators/Object_initializer">ES2015 object property shorthand</a>: + // or, using ES2015 object property shorthand: // console.assert(number % 2 === 0, {number, errorMsg}); } // output: @@ -52,48 +55,14 @@ for (let number = 2; number <= 5; number += 1) { // the # is 4 // the # is 5 // Assertion failed: {number: 5, errorMsg: "the # is not even"} -</pre> +``` -<p>참고로, {{domxref("console.log()")}}의 치환 문자열을 거의 모든 브라우저에서 정상 동작하지만...</p> +자세한 내용은 {{domxref("console")}} 문서의 [콘솔에 텍스트 출력하기](/ko/docs/Web/API/console#콘솔에_텍스트_출력하기)를 참고하세요. -<pre class="brush: js">console.log('the word is %s', 'foo'); -// output: the word is foo -</pre> +## 명세 -<p><code>console.assert()</code>의 치환 문자열은 일부 브라우저에서 동작하지 않습니다.</p> +{{Specifications}} -<pre class="brush: js">console.assert(false, 'the word is %s', 'foo'); -// correct output in Node.js and some browsers -// (e.g. Firefox v60.0.2): -// Assertion failed: the word is foo -// incorrect output in some browsers -// (e.g. Chrome v67.0.3396.87): -// Assertion failed: the word is %s foo -</pre> +## 브라우저 호환성 -<p>{{domxref("console")}} 문서의 <a href="/ko/docs/Web/API/Console#Outputting_text_to_the_console">콘솔에 텍스트 출력하기</a> 항목도 참고하세요.</p> - -<h2 id="명세">명세</h2> - -<table class="standard-table"> - <thead> - <tr> - <th scope="col">Specification</th> - <th scope="col">Status</th> - <th scope="col">Comment</th> - </tr> - </thead> - <tbody> - <tr> - <td>{{SpecName("Console API", "#assert", "console.assert()")}}</td> - <td>{{Spec2("Console API")}}</td> - <td>Initial definition</td> - </tr> - </tbody> -</table> - -<h2 id="브라우저_호환성">브라우저 호환성</h2> - - - -<p>{{Compat("api.Console.assert")}}</p> +{{Compat}} |