{"componentChunkName":"component---src-templates-blog-post-js","path":"/JavaScript/Coercion_in_Javascript/","result":{"data":{"site":{"siteMetadata":{"title":"JULog","author":"[Ju Chan Hwang]","siteUrl":"https://julog.netlify.app","comment":{"disqusShortName":"","utterances":"JuChanHwang/gatsby-starter-bee"},"sponsor":{"buyMeACoffeeId":"jbee"}}},"markdownRemark":{"id":"53516424-4fc9-5bf3-9086-6e3b65eb3d9c","excerpt":"Implicit, Explicit, Nominal, Structuring and Duck Typing 암묵적 타입 변환(Implicit coercion) or 타입 강제 변환(Type coercion) - 자바스크립트 엔진은 표현식을 평가할 때 문맥, 즉 컨텍스트(Context…","html":"<h1 id=\"implicit-explicit-nominal-structuring-and-duck-typing\" style=\"position:relative;\"><a href=\"#implicit-explicit-nominal-structuring-and-duck-typing\" aria-label=\"implicit explicit nominal structuring and duck typing permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Implicit, Explicit, Nominal, Structuring and Duck Typing</h1>\n<h2 id=\"암묵적-타입-변환implicit-coercion-or-타입-강제-변환type-coercion\" style=\"position:relative;\"><a href=\"#%EC%95%94%EB%AC%B5%EC%A0%81-%ED%83%80%EC%9E%85-%EB%B3%80%ED%99%98implicit-coercion-or-%ED%83%80%EC%9E%85-%EA%B0%95%EC%A0%9C-%EB%B3%80%ED%99%98type-coercion\" aria-label=\"암묵적 타입 변환implicit coercion or 타입 강제 변환type coercion permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a><strong>암묵적 타입 변환(Implicit coercion) or 타입 강제 변환(Type coercion)</strong></h2>\n<p>- <strong>자바스크립트 엔진은 표현식을 평가할 때 문맥, 즉 컨텍스트(Context)에 고려하여 암묵적 타입 변환을 실행한다</strong></p>\n<h3 id=\"암묵적-형변환-규칙\" style=\"position:relative;\"><a href=\"#%EC%95%94%EB%AC%B5%EC%A0%81-%ED%98%95%EB%B3%80%ED%99%98-%EA%B7%9C%EC%B9%99\" aria-label=\"암묵적 형변환 규칙 permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a><strong>암묵적 형변환 규칙</strong></h3>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token comment\">// 표현식이 모두 문자열 타입이여야 하는 컨텍스트</span>\n<span class=\"token string\">'10'</span> <span class=\"token operator\">+</span> <span class=\"token number\">2</span>               <span class=\"token comment\">// '102'</span>\n<span class=\"token template-string\"><span class=\"token template-punctuation string\">`</span><span class=\"token string\">1 * 10 = </span><span class=\"token interpolation\"><span class=\"token interpolation-punctuation punctuation\">${</span> <span class=\"token number\">1</span> <span class=\"token operator\">*</span> <span class=\"token number\">10</span> <span class=\"token interpolation-punctuation punctuation\">}</span></span><span class=\"token template-punctuation string\">`</span></span> <span class=\"token comment\">// \"1 * 10 = 10\"</span>\n\n<span class=\"token comment\">// 표현식이 모두 숫자 타입이여야 하는 컨텍스트</span>\n<span class=\"token number\">5</span> <span class=\"token operator\">*</span> <span class=\"token string\">'10'</span> <span class=\"token comment\">// 50</span>\n\n<span class=\"token comment\">// 표현식이 불리언 타입이여야 하는 컨텍스트</span>\n<span class=\"token operator\">!</span><span class=\"token number\">0</span> <span class=\"token comment\">// true</span>\n<span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span><span class=\"token number\">1</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span><span class=\"token operator\">...</span><span class=\"token punctuation\">}</span></code></pre></div>\n<blockquote>\n<p>이처럼 표현식을 평가할 때 문맥, 즉 컨텍스트에 부합하지 않는 다양한 상황이 발생할 수 있다. 이때 자바스크립트는 가급적 에러를 발생시키지 않도록 암묵적 타입 변환을 통해 표현식을 평가한다.</p>\n</blockquote>\n<blockquote>\n<p>암묵적 타입 변환은 변수 값을 재할당해서 변경하는 것이 아니라 자바스크립트 엔진이 표현식을 에러없이 평가하기 위해 기존 값을 바탕으로 새로운 타입의 값을 만들어 단 한번 사용하고 버린다. 위 예제의 경우, 자바스크립트 엔진은 표현식 x + ‘‘을 평가하기 위해 변수 x의 숫자 값을 바탕으로 새로운 문자열 값 ‘10’을 생성하고 이것으로 표현식 ‘10’ + ‘‘를 평가한다. 이때 자동 생성된 문자열 ‘10’은 표현식의 평가가 끝나면 아무도 참조하지 않으므로 가비지 컬렉터에 의해 메모리에서 제거된다.</p>\n</blockquote>\n<h2 id=\"명시적-타입-변환explicit-coercion-or-타입-캐스팅type-casting\" style=\"position:relative;\"><a href=\"#%EB%AA%85%EC%8B%9C%EC%A0%81-%ED%83%80%EC%9E%85-%EB%B3%80%ED%99%98explicit-coercion-or-%ED%83%80%EC%9E%85-%EC%BA%90%EC%8A%A4%ED%8C%85type-casting\" aria-label=\"명시적 타입 변환explicit coercion or 타입 캐스팅type casting permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a><strong>명시적 타입 변환(Explicit coercion) or 타입 캐스팅(Type casting)</strong></h2>\n<p>- 개발자가 직접 스크립트를 이용해 어떤 형으로 바꿀지 명시해주는 것</p>\n<p>- 문자를 숫자로, 숫자를 문자로 변환</p>\n<p>- 모든 형변환은 전역함수 또는 특정 클래스에서 제공하는 메서드를 이용해서 처리됨</p>\n<h3 id=\"명시적-형변환-방법\" style=\"position:relative;\"><a href=\"#%EB%AA%85%EC%8B%9C%EC%A0%81-%ED%98%95%EB%B3%80%ED%99%98-%EB%B0%A9%EB%B2%95\" aria-label=\"명시적 형변환 방법 permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a><strong>명시적 형변환 방법</strong></h3>\n<ol>\n<li>문자를 숫자로</li>\n</ol>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token comment\">// 정수형</span>\n<span class=\"token keyword\">var</span> value <span class=\"token operator\">=</span> <span class=\"token string\">\"123.456\"</span><span class=\"token punctuation\">;</span>\n<span class=\"token function\">parseInt</span><span class=\"token punctuation\">(</span>value<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token comment\">//결과 : 123</span>\n \n<span class=\"token keyword\">var</span> value <span class=\"token operator\">=</span> <span class=\"token string\">\"123\"</span><span class=\"token punctuation\">;</span>\n<span class=\"token function\">Number</span><span class=\"token punctuation\">(</span>value<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token comment\">// 결과 : 123</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token comment\">// 실수형</span>\n<span class=\"token keyword\">var</span> value <span class=\"token operator\">=</span> <span class=\"token string\">\"123.456\"</span><span class=\"token punctuation\">;</span>\n<span class=\"token function\">parseFloat</span><span class=\"token punctuation\">(</span>value<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token comment\">// 결과 : 123.456</span>\n \n<span class=\"token keyword\">var</span> value <span class=\"token operator\">=</span> <span class=\"token string\">\"123.456\"</span><span class=\"token punctuation\">;</span>\n<span class=\"token function\">Number</span><span class=\"token punctuation\">(</span>value<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token comment\">// 결과 : 123.456</span></code></pre></div>\n<ol start=\"2\">\n<li>숫자를 문자로</li>\n</ol>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token comment\">// 일반 문자형 : String() 사용</span>\n<span class=\"token keyword\">var</span> value <span class=\"token operator\">=</span> <span class=\"token number\">15</span><span class=\"token punctuation\">;</span>\n<span class=\"token function\">String</span><span class=\"token punctuation\">(</span>value<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token comment\">// 결과 : 15</span>\n\n<span class=\"token comment\">// 16진수 문자형 : Number.toString() 사용</span>\n<span class=\"token keyword\">var</span> value <span class=\"token operator\">=</span> <span class=\"token number\">15</span><span class=\"token punctuation\">;</span>\nvalue<span class=\"token punctuation\">.</span><span class=\"token function\">toString</span><span class=\"token punctuation\">(</span><span class=\"token number\">16</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token comment\">// 결과 : f</span>\n\n<span class=\"token comment\">// 실수 문자형 : Number.toFixed() 사용</span>\n<span class=\"token keyword\">var</span> value <span class=\"token operator\">=</span> <span class=\"token number\">123.456</span><span class=\"token punctuation\">;</span>\nvalue<span class=\"token punctuation\">.</span><span class=\"token function\">toFixed</span><span class=\"token punctuation\">(</span><span class=\"token number\">2</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token comment\">// 결과 : 123.46 반올림 발생</span></code></pre></div>\n<blockquote>\n<p>명시적 타입 변환은 타입을 변경하겠다는 개발자의 의지가 코드에 명백히 드러난다. 하지만 암묵적 타입 강제 변환은 자바스크립트 엔진에 의해 암묵적으로, 즉 드러나지 않게 타입이 자동 변환되기 때문에 타입을 변경하겠다는 개발자의 의지가 코드에 명백히 나타나지 않는다.</p>\n<p>따라서 자신이 작성한 코드에서 암묵적 타입 변환이 발생하는지, 발생한다면 어떤 타입의 어떤 값으로 변환되는지, 그리고 타입 변환된 값으로 표현식은 어떻게 평가될 것인지 예측 가능해야 한다. 만약 예측하지 못하거나 예측한 내용이 결과와 일치하지 않는다면 버그를 생산할 가능성이 높아진다.</p>\n<p>그렇다면 명시적 타입 변환 만을 사용하고 암묵적 타입 변환은 발생하지 않도록 코드를 작성하면 어떨까? 좋은 생각이긴 하지만 이러한 논리는 옳지 않다. 때로는 명시적 타입 변환보다 암묵적 타입 변환이 가독성 면에서 더 좋을 수도 있다. 예를 들어 자바스크립트 문법을 잘 이해하고 있는 개발자에게는 <code class=\"language-text\">(10).toString()</code>보다 <code class=\"language-text\">10 + ''</code>이 더욱 간결하고 이해하기 쉬울 수 있다.</p>\n<p>중요한 것은 코드를 예측할 수 있어야 한다는 것이다. 동료가 작성한 코드를 정확히 이해할 수 있어야 하고 자신의 코드는 타인에 의해 쉽게 이해될 수 있어야 한다. 이를 위해 타입 변환이 어떻게 동작하는지 정확히 이해하고 사용하도록 하자</p>\n</blockquote>\n<h3 id=\"why\" style=\"position:relative;\"><a href=\"#why\" aria-label=\"why permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>why?</h3>\n<blockquote>\n<h2 id=\"why-is-it-doing-it-wrong\" style=\"position:relative;\"><a href=\"#why-is-it-doing-it-wrong\" aria-label=\"why is it doing it wrong permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Why is it doing it wrong?</h2>\n<p>자바스크립트가 처음 만들어진 시점에 자바스크립트의 가장 큰 목적 하나가 “web을 정상적으로 동작시키자” 였다.</p>\n<p>The simple reason is history. JavaScript has a long, weird, winding history from when Brendan Eich originally wrote the first prototype in 10 days at Netscape in 1995.</p>\n<p>Since then, anything that hasn’t been “fixed” has only one reason. JavaScript has one simple rule — don’t break the web. This is why strange things like <code class=\"language-text\">typeof null === 'object'</code> exist. This is outside the scope of this article, so more on why that is <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/typeof#null\">here</a>.</p>\n</blockquote>\n<h2 id=\"같이-풀어볼-예제들\" style=\"position:relative;\"><a href=\"#%EA%B0%99%EC%9D%B4-%ED%92%80%EC%96%B4%EB%B3%BC-%EC%98%88%EC%A0%9C%EB%93%A4\" aria-label=\"같이 풀어볼 예제들 permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>같이 풀어볼 예제들!!</h2>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token operator\">-</span> <span class=\"token number\">1</span> <span class=\"token operator\">+</span> <span class=\"token string\">\"1\"</span>\n<span class=\"token operator\">-</span> <span class=\"token number\">11</span> <span class=\"token operator\">-</span> <span class=\"token string\">\"1\"</span>\n<span class=\"token operator\">-</span> <span class=\"token number\">3</span> <span class=\"token operator\">*</span> <span class=\"token string\">\"3\"</span>\n<span class=\"token operator\">-</span> <span class=\"token string\">\"6\"</span> <span class=\"token operator\">/</span> <span class=\"token number\">3</span>\n<span class=\"token operator\">-</span> <span class=\"token number\">1</span> <span class=\"token operator\">+</span> <span class=\"token string\">\"2\"</span> <span class=\"token operator\">+</span> <span class=\"token number\">1</span>\n\n<span class=\"token operator\">-</span> <span class=\"token boolean\">true</span> <span class=\"token operator\">+</span> <span class=\"token boolean\">false</span>\n<span class=\"token operator\">-</span> <span class=\"token boolean\">false</span> <span class=\"token operator\">*</span> <span class=\"token boolean\">true</span>\n<span class=\"token operator\">-</span> <span class=\"token number\">5</span> <span class=\"token operator\">+</span> <span class=\"token boolean\">true</span>\n\n<span class=\"token keyword\">const</span> foo <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span>\n  <span class=\"token function-variable function\">valueOf</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token number\">2</span>\n<span class=\"token punctuation\">}</span>\n<span class=\"token number\">3</span> <span class=\"token operator\">+</span> foo <span class=\"token comment\">// 5</span>\n<span class=\"token number\">4</span> <span class=\"token operator\">*</span> foo <span class=\"token comment\">// 8</span>\n\n<span class=\"token keyword\">const</span> bar <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span>\n  <span class=\"token function-variable function\">toString</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token string\">\" promise is a boy :)\"</span>\n<span class=\"token punctuation\">}</span>\n<span class=\"token number\">1</span> <span class=\"token operator\">+</span> bar <span class=\"token comment\">// \"1 promise is a boy :)\"</span>\n\n\n<span class=\"token number\">4</span> <span class=\"token operator\">*</span> <span class=\"token punctuation\">[</span><span class=\"token punctuation\">]</span> <span class=\"token comment\">// 0</span>\n<span class=\"token number\">4</span> <span class=\"token operator\">*</span> <span class=\"token punctuation\">[</span><span class=\"token number\">2</span><span class=\"token punctuation\">]</span> <span class=\"token comment\">// 8</span>\n<span class=\"token number\">4</span> <span class=\"token operator\">+</span> <span class=\"token punctuation\">[</span><span class=\"token number\">2</span><span class=\"token punctuation\">]</span> <span class=\"token comment\">// \"42\"</span>\n<span class=\"token number\">4</span> <span class=\"token operator\">+</span> <span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">]</span> <span class=\"token comment\">// \"41,2\"</span>\n<span class=\"token number\">4</span> <span class=\"token operator\">*</span> <span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">]</span> <span class=\"token comment\">// NaN</span>\n\n<span class=\"token string\">\"string\"</span> <span class=\"token operator\">?</span> <span class=\"token number\">4</span> <span class=\"token operator\">:</span> <span class=\"token number\">1</span> <span class=\"token comment\">// 4</span>\n<span class=\"token keyword\">undefined</span> <span class=\"token operator\">?</span> <span class=\"token number\">4</span> <span class=\"token operator\">:</span> <span class=\"token number\">1</span> <span class=\"token comment\">// 1</span></code></pre></div>","frontmatter":{"title":"Coercion In Javascript","date":"September 04, 2019"}}},"pageContext":{"slug":"/JavaScript/Coercion_in_Javascript/","previous":{"fields":{"slug":"/JavaScript/Call_Stack/"},"frontmatter":{"title":"Call Stack","category":"JavaScript","draft":false}},"next":{"fields":{"slug":"/JavaScript/Function_Scope_Block_Scope_and_Lexical_Scope/"},"frontmatter":{"title":"Function Scope, Block Scope and Lexical Scope","category":"JavaScript","draft":false}}}},"staticQueryHashes":["3128451518","96099027"]}