<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/"
    xmlns:atom="http://www.w3.org/2005/Atom" xmlns:media="http://search.yahoo.com/mrss/" version="2.0">
    <channel>
        
        <title>
            <![CDATA[ Janghan Park - freeCodeCamp.org ]]>
        </title>
        <description>
            <![CDATA[ Browse thousands of programming tutorials written by experts. Learn Web Development, Data Science, DevOps, Security, and get developer career advice. ]]>
        </description>
        <link>https://www.freecodecamp.org/korean/news/</link>
        <image>
            <url>https://cdn.freecodecamp.org/universal/favicons/favicon.png</url>
            <title>
                <![CDATA[ Janghan Park - freeCodeCamp.org ]]>
            </title>
            <link>https://www.freecodecamp.org/korean/news/</link>
        </image>
        <generator>Eleventy</generator>
        <lastBuildDate>Fri, 22 May 2026 15:16:06 +0000</lastBuildDate>
        <atom:link href="https://www.freecodecamp.org/korean/news/author/janghan/rss.xml" rel="self" type="application/rss+xml" />
        <ttl>60</ttl>
        
            <item>
                <title>
                    <![CDATA[ 2022년에 알아야 할 10가지 리액트 인터뷰 질문 ]]>
                </title>
                <description>
                    <![CDATA[  리액트 지식에 자신이 있으신가요? 한번 시험해 보세요! 면접을 보는 상황이든 아니든 2022년에 리액트 개발자로서 알아야 할 10가지 주요 질문들을 준비했습니다. 이 질문들은 리액트의 핵심 개념부터 특정 기능을 언제 사용해야 하는지에 대한 실질적인 이해까지 모두 포함합니다. 이 가이드를 통해 최상의 결과를 얻으시려면 정답을 보기 전에 꼭 먼저 모든 질문에 스스로 ]]>
                </description>
                <link>https://www.freecodecamp.org/korean/news/2022nyeone-alaya-hal-10gaji-riaegteu-inteobyu-jilmun/</link>
                <guid isPermaLink="false">653061bedbcb8a03ea44a170</guid>
                
                    <category>
                        <![CDATA[ React ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ Janghan Park ]]>
                </dc:creator>
                <pubDate>Thu, 19 Oct 2023 12:14:43 +0000</pubDate>
                <media:content url="https://www.freecodecamp.org/korean/news/content/images/2023/10/react-interview-questions-1.png" medium="image" />
                <content:encoded>
                    <![CDATA[ <p data-test-label="translation-intro">
        <strong>기사 원문:</strong> <a href="https://www.freecodecamp.org/news/react-interview-questions-to-know/" target="_blank" rel="noopener noreferrer" data-test-label="original-article-link">10 React Interview Questions You Should Know in 2022</a>
      </p><h4></h4><h3 id="-">리액트 지식에 자신이 있으신가요? 한번 시험해 보세요!</h3><p>면접을 보는 상황이든 아니든 2022년에 리액트 개발자로서 알아야 할 10가지 주요 질문들을 준비했습니다.</p><p>이 질문들은 리액트의 핵심 개념부터 특정 기능을 언제 사용해야 하는지에 대한 실질적인 이해까지 모두 포함합니다.</p><p>이 가이드를 통해 최상의 결과를 얻으시려면 정답을 보기 전에 꼭 먼저 모든 질문에 스스로 답해보세요.</p><p>그럼 시작해 봅시다!</p><p><br></p><h2 id="1-">1. 리액트는 무엇이고 언제 사용합니까?</h2><p>리액트는 라이브러리이지 프레임워크가 아닙니다.</p><p>리액트는 자바스크립트의 모든 기능을 제공합니다. 또한 리액트의 기본 특징들은 우리가 애플리케이션을 만들거나 그것에 대해 생각하는 방식을 향상시켜줍니다.</p><ul><li>JSX 와 같은 도구로 유저 인터페이스를 <strong>쉽게 만드는 방법</strong>을 제공합니다.</li><li>정적인 HTML이 할 수 없는 <strong>유저 인터페이스 공유</strong>를 쉽게 만들어 주는 컴포넌트를 제공합니다.</li><li>리액트 훅을 사용하여 컴포넌트들 사이에 <strong>재사용 가능한 동작</strong>을 만들 수 있습니다.</li><li>리액트는 직접 DOM을 건드리지 않고 데이터가 바뀔 때 UI를 업데이트합니다.</li></ul><p><strong>보너스 팁</strong>: 리액트에는 Next.js나 Gaysby처럼 애플리케이션을 만들 때 필요한 모든 기능을 제공하는 프레임워크들이 있습니다.</p><p>리액트는 특히 싱글 페이지 애플리케이션(SPA)을 위해 만들어졌습니다. 하지만 정적인 사이트부터 모바일 애플리케이션까지 모든 것을 똑같은 리액트 방식으로 만들 수 있습니다.</p><p><br></p><h2 id="2-jsx-">2. JSX는 무엇입니까?</h2><p>JSX는 HTML의 간단한 문법을 사용하지만 기능과 자바스크립트의 동적 요소 가 더해진 유저 인터페이스를 만드는 방법 중 하나입니다.</p><p>짧게 말해, 리액트 애플리케이션을 조직하는 <strong>HTML + Javascript</strong>입니다.</p><p>JSX는 HTML처럼 보이지만 사실은 자바스크립트 함수 호출입니다.</p><p>JSX 안에서 <code>div</code>를 사용하는 것은<code>React.createElement()</code>를 호출하는 것과 동일합니다.</p><p>직접 <code>React.createElement()</code>를 호출해 유저 인터페이스를 만들 수 있지만 요소들을 계속 더할수록 만들어놓은 구조를 읽는 게 계속해서 어려워집니다.</p><p><strong>웹 브라우저는 JSX를 이해할 수 없습니다.</strong> 그래서 보통 <strong>Babel</strong>이라고 불리는 컴파일러를 사용합니다. <strong>Babel</strong>은 HTML처럼 보이는 것을 자바스크립트 함수 호출로 변환하여 브라우저가 이해할 수 있게 만들어 줍니다.</p><p><br></p><h2 id="3-">3. 리액트 컴포넌트에 어떻게 데이터를 전달합니까?</h2><p>리액트 컴포넌트에 데이터를 전달하는 방법은 크게 두 가지가 있습니다.</p><ol><li>Props</li><li>Context API</li></ol><p>Props는 가까이에 있는 컴포넌트의 부모로부터 전달되는 데이터입니다. Props는 자식 컴포넌트에 선언되며 아무 이름과 유효한 값을 받을 수 있습니다.</p><pre><code class="language-jsx">function Blog() {
    const post = { title: "My Blog Post!" };

    return &lt;BlogPost post={post} /&gt;;
}
</code></pre><p>Props는 자식 컴포넌트에서 사용되고 자식 <strong>객체의 프로퍼티</strong>로 사용 가능합니다.</p><pre><code class="language-jsx">function BlogPost(props) {
    return &lt;h1&gt;{props.post.title}&lt;/h1&gt;
}
</code></pre><p>Props는 순전한 객체의 프로퍼티이기 때문에 더 쉬운 접근을 위해 디스트럭팅 (destructing) 될 수 있습니다.</p><pre><code class="language-jsx">function BlogPost({ post }) {
    return &lt;h1&gt;{post.title}&lt;/h1&gt;
}
</code></pre><p>Context는 context provider에서 전달되는 데이터이며 context를 사용하는 컴포넌트에서 사용됩니다.</p><p>Context를 사용하면 Props 없이 애플리케이션 내 어디서나 데이터에 접근할 수 있습니다. (context provider 가 전체 컨포넌트 트리를 감쌀 경우)</p><p>Context 데이터는 <code>Context.Provider</code>를 이용해 <code>value</code> prop 을 통해 전달되며 이 데이터들은 <code>Context.Consumer</code> 또는 <code>useContext</code> 훅 (hook) 을 이용해 사용됩니다.</p><pre><code class="language-jsx">import { createContext, useContext } from 'react';

const PostContext = createContext()

function App() {
    const post = { title: "My Blog Post!" };

    return (
        &lt;PostContext.Provider value={post}&gt;
            &lt;Blog /&gt;
        &lt;/PostContext.Provider&gt;
    );
}

function Blog() {
    return &lt;BlogPost /&gt;
}

function BlogPost() {
    const post = useContext(PostContext)

    return &lt;h1&gt;{post.title}&lt;/h1&gt;
}
</code></pre><p><br></p><h2 id="4-porps-state-">4. porps 와 state의 차이는 무엇입니까?</h2><p>State는 리액트 컴포넌트 안에서 읽고 업데이트 가능한 값입니다.</p><p>Props는 리액트 컴포넌트에 전달되는 읽기만 가능한 값입니다.<br><br><br>(Props는 업데이트 되면 안 됩니다.)</p><p>props는 컴포넌트 밖에 존재하는 함수의 인자로 생각할 수 있습니다. 반면에 state는 계속해서 바뀌는 값이며 컴포넌트 안에 존재하고 선언됩니다.</p><p>State 와 porps는 변경사항으로 인해 존재하는 컴포넌트가 다시 렌더링 된다는 점에서 유사합니다.</p><p><br></p><h2 id="5-fragment-">5. 리액트 fragment는 왜 사용합니까?</h2><p>fragment는 리액트에 있는 특별한 특징입니다. fragment를 사용하면 DOM에서 노드 (node) 없이 자식 요소나 자식 컴포넌트 그룹을 만들 수 있습니다.</p><p>fragment 문법은 빈 태그 <code>&lt;&gt;&lt;/&gt;</code>처럼 생겼거나 <code>React.Fragment</code>로 사용됩니다.</p><p>간단히 말하면, 때로는 여러 리액트 요소들을 한 부모 요소에 넣어야 하지만 <code>div</code>와 같은 일반적인 HTML 요소를 사용하고 싶지 않을 때입니다.</p><p>테이블을 만든다고 가정해 보면 아래는 올바르지 않은 HTML입니다.</p><pre><code class="language-jsx">function Table() {
   return (
     &lt;table&gt;
       &lt;tr&gt;
         &lt;Columns /&gt;
       &lt;/tr&gt;
     &lt;/table&gt;
   );
}

function Columns() {
   return (
     &lt;div&gt;
       &lt;td&gt;Column 1&lt;/td&gt;
       &lt;td&gt;Column 2&lt;/td&gt;
     &lt;/div&gt;
   );
}
</code></pre><p><code>Columns</code> 컴포넌트 안에서 <code>div</code> 요소 대신 fragment를 사용하면 이 문제를 해결할 수 있습니다.</p><pre><code class="language-jsx">function Columns() {
   return (
     &lt;&gt;
       &lt;td&gt;Column 1&lt;/td&gt;
       &lt;td&gt;Column 2&lt;/td&gt;
     &lt;/&gt;
   );
}
</code></pre><p>fragment를 사용하는 또 다른 이유는 HTML 요소를 추가할 때 CSS 스타일이 적용되는 방법이 바뀔 수 있기 때문입니다.</p><p><br></p><h2 id="6-list-key-">6. 리액트 리스트 (list)에 왜 key를 사용해야 합니까?</h2><p>Key는 고유한 값입니다. <code>.map()</code> 함수를 사용하여 요소나 컴포넌트를 루프 (loop) 할 때 반드시 <code>key</code> prop 을 전달해야 합니다.</p><p>요소를 매핑하는 경우 아래와 같을 겁니다.</p><pre><code class="language-jsx">posts.map(post =&gt; &lt;li key={post.id}&gt;{post.title}&lt;/li&gt;)
</code></pre><p>컴포넌트를 맵핑하는 경우</p><pre><code class="language-jsx">posts.map(post =&gt; &lt;li key={post.id}&gt;{post.title}&lt;/li&gt;)
</code></pre><p>둘 다의 경우 고유한 값인 key를 추가해야 합니다. 아니면 리액트가 경고 메시지를 보냅니다.</p><p>왜 그럴까요? key는 요소나 컴포넌트가 어느 리스트 (list)에 있는지 정의하기 때문입니다.</p><p>key를 사용하지 않을 경우 리스트에 있는 아이템을 어떤 방법으로 추가하거나 수정해서 바꾸려고 할 때 리액트가 바뀌어야 하는 순서를 알 수 없습니다.</p><p>리액트는 모든 DOM 비즈니스 업데이트를 책임지지만 (가상 DOM 사용) 이를 <strong>제대로 업데이트하려면 key 가 필요합니다</strong>.</p><p><br></p><h2 id="7-ref-">7. ref는 무엇이고 어떻게 사용해야 합니까?</h2><p>리액트에서 ref는 DOM 요소의 참조입니다.</p><p>Ref는 <code>useRef</code> 훅 (hook) 을 이용해 생성되며 바로 변수에 담을 수 있습니다.</p><p>그리고 이 변수는 리액트 요소 (컴포넌트 아님)에 근본적인 HTML 요소 (div, span 등등)의 참조를 얻기 위해 전달됩니다.</p><p>참조된 요소와 프로퍼티는 ref의 <strong>.current 프로퍼티</strong>를 통해 사용 가능합니다.</p><pre><code class="language-jsx">import { useRef } from 'react'

function MyComponent() {
   const ref = useRef();

   useEffect(() =&gt; {
     console.log(ref.current) // div 의 참조
   }, [])

   return &lt;div ref={ref} /&gt;
}
</code></pre><p>Ref는 가끔 "escape hatch (피난용 비상구)"라고 불리고 DOM 요소와 직접적으로 사용됩니다 그리고 리액트를 통해 할 수 없는 특정 연산 (input 태그를 포커스 하거나 클리어 등) 을 가능하게 해줍니다.</p><p><br></p><h2 id="8-useeffect-">8. useEffect는 왜 사용합니까?</h2><p>리액트 컴포넌트에서 <code>useEffect</code> 훅 (hook) 은 사이드 이펙트 (side effect)를 위해 사용됩니다.</p><p><strong>사이든 이펙트 (side effect)</strong> 는 "바깥세상 (outside world)" 나 리액트 context 밖에 존재하는 것을 담당하는 연산입니다.</p><p>사이트 이펙트 (side effect)의 예로는 외부 API 포인트로 GET이나 POST 요청을 보내거나 브라우저 API <code>window.navigator</code> 또는 <code>document.getElementById()</code>를 사용하는 것입니다.</p><p>리액트 컴포넌트 바디안에서 바로 저 연산들을 할 수 없습니다. <code>useEffect</code>는 사이드 이펙트 (side effect)를 수행할 수 있는 함수와 dependency 배열을 제공합니다. dependency 배열에는 함수가 의존하는 값들이 들어갑니다.</p><p>만약 dependency 배열의 값이 바뀌면 이펙트 (effect) 함수는 다시 호출됩니다.</p><p><br></p><h2 id="9-context-redux-">9. 리액트 Context 나 Redux는 언제 사용합니까?</h2><blockquote>Redux는 아마 리액트에서 가장 널리 사용되는 서드파티 (third party) global state 라이브러리 일 것입니다. 그러나 이 질문의 경우 "Redux"라는 단어를 다른 global state 라이브러리로 바꿀 수 있습니다.</blockquote><p>리액트 Context는 <strong>Prop 을 활용</strong>하지 않고 애플리케이션 내에서 데이터를 사용할 수 있습니다.</p><p>리액트 Context는 데이터가 필요하지 않는 컴포넌트를 통해 데이터를 전달할 때 생기는 **"프롭 드릴링 (props drilling)"**이라는 문제를 예방합니다.</p><p>대신 Context를 이용하면 데이터를 필요로 하는 컴포넌트에 정확히 사용할 수 있습니다.</p><p>Context를 사용하면 데이터를 데이터를 가져오거나 읽기만 할 뿐이지만 Redux 나 다른 서드파티 (third party) state library는 <strong>읽기와 업데이트가 가능합니다</strong>.</p><p><strong>State 업데이트 용으로 만들어지지 않았기 때문에</strong> Context는 Redux 와 같은 서드파티 라이브러리 대체재가 아닙니다 그 이유는 Context를 통해 사용되는 데이터가 업데이트될 때마다 모든 자식 컴포넌트는 다시 렌더링 되고 퍼포먼스에 큰 영향을 끼치기 때문입니다.</p><p><br></p><h2 id="10-usecallback-usememo-">10. useCallback 과 useMemo는 왜 사용합니까?</h2><p><code>useCallback</code> 과 <code>useMemo</code>는 컴포넌트 퍼포먼스를 향상시키기 위해 사용됩니다.</p><p><code>useCallback</code> 은 매 렌더링마다 컴포넌트 바디안에서 선언된 함수가 재생성되는 것을 예방합니다.</p><p>이것은 불필요한 퍼포먼스 문제를 야기할 수 있습니다. 특히 자식 컴포넌트에 전달되는 콜백 (callback) 함수들입니다.</p><p>반면에 <code>useMemo</code>는 무거운 연산 작업을 기업합니다.</p><p>메모이제이션 (memoization)은 인자가 변경되지 않는 경우 계산한 과거 값을 기억할 수 있는 함수의 기술적 용어입니다. 만약 인자가 그대로라면 함수는 기억된 값을 반환합니다.</p><p>다른 말로 하면 많은 계산 자원 (computing resources)를 필요로 하는 계산이 있을 경우 최대한 적게 계산을 하게 됩니다.</p><p>이런 경우 함수를 반환하는 <code>useCallback</code> 대신 &nbsp;값을 반환하는 <code>useMemo</code>를 사용할 수 있습니다.</p><p><br></p><h2 id="--1">전문적인 리액트 개발자 되기</h2><p>리액트는 어렵습니다. 혼자 모든 것을 알아내려고 하지 않아도 됩니다.</p><p>기록적인 시간에 목표 달성을 돕기 위해 리액트 강의에 리액트에 관해 아는 모든 것을 담았습니다.</p><h3 id="introducing-the-react-bootcamp"><a href="https://www.reactbootcamp.com/">Introducing: The React Bootcamp</a></h3><p>제가 리액트를 배우기 시작했을 때 알았으면 하는 강의입니다.</p><p>아래를 클릭하여 리액트 부트 캠프를 경험해 보세요.</p><figure class="kg-card kg-image-card"><img src="https://reedbarger.nyc3.digitaloceanspaces.com/reactbootcamp/react-bootcamp-cta-alt.png" class="kg-image" alt="react-bootcamp-cta-alt" width="600" height="400" loading="lazy"></figure> ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ 자바스크립트에서 문자열을 숫자로 변환하는 방법 ]]>
                </title>
                <description>
                    <![CDATA[  자바스크립트에서 문자열을 숫자로 변환하는 방법은 여러 가지가 있습니다. 코드로는 어떻게 생겼을까요? 이번 글에서는 문자열을 숫자로 변환하는 11가지 방법을 소개합니다. Number() 함수를 이용해 문자열을 숫자로 변환하는 방법 문자열을 숫자로 변환하는 한 가지 방법은 Number() 함수를 사용하는 것입니다.아래 예시에 "12"라는 문자열 값을 가진 quantity가 있습니다. const quantity = "12"; quantity를 typeof ]]>
                </description>
                <link>https://www.freecodecamp.org/korean/news/how-to-convert-a-string-to-a-number-in-javascript/</link>
                <guid isPermaLink="false">63a5072d6ff1bc0647f6d34e</guid>
                
                    <category>
                        <![CDATA[ JavaScript ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ Janghan Park ]]>
                </dc:creator>
                <pubDate>Fri, 23 Dec 2022 07:28:23 +0000</pubDate>
                <media:content url="https://www.freecodecamp.org/korean/news/content/images/2022/12/thumb.jpeg" medium="image" />
                <content:encoded>
                    <![CDATA[ <p data-test-label="translation-intro">
        <strong>기사 원문:</strong> <a href="https://www.freecodecamp.org/news/how-to-convert-a-string-to-a-number-in-javascript/" target="_blank" rel="noopener noreferrer" data-test-label="original-article-link">How to Convert a String to a Number in JavaScript</a>
      </p><p></p><h3 id="-">자바스크립트에서 문자열을 숫자로 변환하는 방법은 여러 가지가 있습니다. 코드로는 어떻게 생겼을까요?</h3><p><br>이번 글에서는 문자열을 숫자로 변환하는 11가지 방법을 소개합니다.</p><h2 id="number-"><code>Number()</code> <b>함수를 이용해 문자열을 숫자로 변환하는 방법</b></h2><p>문자열을 숫자로 변환하는 한 가지 방법은 <code>Number()</code> 함수를 사용하는 것입니다.아래 예시에 <code>"12"</code>라는 문자열 값을 가진 <code>quantity</code>가 있습니다.</p><p></p><pre><code class="language-js">const quantity = "12";
</code></pre><p></p><p><code>quantity</code>를 <code>typeof</code> 연산자를 통해 실행해 보면 문자열 타입을 반환합니다.</p><pre><code class="language-js">console.log(typeof quantity);
</code></pre><figure class="kg-card kg-image-card"><img src="https://www.freecodecamp.org/news/content/images/2022/05/Screen-Shot-2022-05-01-at-9.50.17-AM.png" class="kg-image" alt="Screen-Shot-2022-05-01-at-9.50.17-AM" width="600" height="400" loading="lazy"></figure><p></p><p>아래 예시처럼 <code>Number</code> 함수를 이용해 <code>quantitiy</code>를 변환할 수 있습니다.</p><pre><code class="language-js">Number(quantity);
</code></pre><p></p><p>다시 <code>typeof</code> 연산자를 이용해 이제는 숫자 타입이라는 것을 확인할 수 있습니다.</p><pre><code class="language-js">console.log(typeof Number(quantity));
</code></pre><p><br>숫자로 변환될 수 없는 값을 넘겨준다면 <code>NaN</code>(Not a Number)를 반환합니다.</p><pre><code class="language-js">console.log(Number("awesome"));
</code></pre><figure class="kg-card kg-image-card"><img src="https://www.freecodecamp.org/news/content/images/2022/05/Screen-Shot-2022-05-01-at-10.00.34-AM.png" class="kg-image" alt="Screen-Shot-2022-05-01-at-10.00.34-AM" width="600" height="400" loading="lazy"></figure><p><br><br></p><h2 id="parseint-"><code>parseInt()</code> <b>함수를 이용해 문자열을 숫자로 변환하는 방법</b></h2><p><br>문자열을 숫자로 변환하는 또 다른 방법으로는 <code>parseInt()</code> 함수를 이용하는 것입니다. 이 함수는 문자열과 기수(radix, base)를 인자로 받습니다.</p><p>기수는 수의 진법 체계에서 기준이 되는 값을 나타내는 2부터 36까지의 정수입니다. 예를 들어 기수를 2로 하면 2진수가 되고, 기수 값을 10으로 하면 10진수가 됩니다.</p><p>문자열을 숫자로 변한 해보기 위해 위에 예제에서 사용했던 <code>quantity</code>를 사용해 보겠습니다.</p><pre><code class="language-js">const quantity = "12";
console.log(parseInt(quantity, 10));
</code></pre><p></p><p><code>quantity</code> 변수를 <code>"12.99"</code>로 바꾸면 무슨 일이 일어날까요? <code>parseInt()</code> 가 그대로 숫자 12.99를 반환할까요?<br></p><pre><code class="language-js">const quantity = "12.99";
console.log(parseInt(quantity, 10));
</code></pre><p></p><figure class="kg-card kg-image-card"><img src="https://www.freecodecamp.org/news/content/images/2022/05/Screen-Shot-2022-05-01-at-10.45.08-AM.png" class="kg-image" alt="Screen-Shot-2022-05-01-at-10.45.08-AM" width="600" height="400" loading="lazy"></figure><p><br>위에서 볼 수 있듯이 결과는 어림한 정수입니다. 만약 반환값으로 실수를 받고 싶다면 <code>parseFloat()</code>를 사용하면 됩니다.</p><p></p><h2 id="parsefloat-"><code>parseFloat()</code> <b>함수를 이용해 문자열을 숫자로 변환하는 방법</b></h2><p><br><code>parseFloat</code> 함수는 값을 받아 실수를 반환합니다. 실수의 예로는 12.99 또는 3.14와 같은 것들이 있습니다.</p><p></p><p><code>parseFloat()</code>를 이용해 위의 예제를 수정하면 실수인 12.99가 반환됩니다.<br></p><pre><code class="language-js">const quantity = "12.99";
console.log(parseFloat(quantity));
</code></pre><p></p><figure class="kg-card kg-image-card"><img src="https://www.freecodecamp.org/news/content/images/2022/05/Screen-Shot-2022-05-01-at-10.55.03-AM.png" class="kg-image" alt="Screen-Shot-2022-05-01-at-10.55.03-AM" width="600" height="400" loading="lazy"></figure><p><br></p><p>문자열 앞 혹은 뒤에 공백이 있어도 <code>parseFloat()</code>는 이전과 같이 문자열을 실수로 변환합니다.<br></p><pre><code class="language-js">const quantity = "   12.99    ";
console.log(parseFloat(quantity));
</code></pre><p><br></p><figure class="kg-card kg-image-card"><img src="https://www.freecodecamp.org/news/content/images/2022/05/Screen-Shot-2022-05-01-at-11.05.35-AM.png" class="kg-image" alt="Screen-Shot-2022-05-01-at-11.05.35-AM" width="600" height="400" loading="lazy"></figure><p></p><p>문자열의 첫 글자가 숫자로 변환할 수 없는 경우 <code>NaN</code>을 반환합니다.</p><pre><code class="language-js">const quantity = "F12.99";
console.log(parseFloat(quantity));
</code></pre><p><br></p><figure class="kg-card kg-image-card"><img src="https://www.freecodecamp.org/news/content/images/2022/05/Screen-Shot-2022-05-01-at-11.08.33-AM.png" class="kg-image" alt="Screen-Shot-2022-05-01-at-11.08.33-AM" width="600" height="400" loading="lazy"></figure><p><br></p><h2 id="--1">(<code>+</code>) <b>단항 더하기 연산자를 이용해 문자열을 숫자로 변환하는 방법</b></h2><p></p><p>단항 더하기 연산자(<code>+</code>)는 문자열을 숫자로 반환하며 피연산자 앞에 위치합니다.</p><pre><code class="language-js">const quantity = "12";
console.log(+quantity);
</code></pre><p></p><figure class="kg-card kg-image-card"><img src="https://www.freecodecamp.org/news/content/images/2022/05/Screen-Shot-2022-05-01-at-11.14.51-AM.png" class="kg-image" alt="Screen-Shot-2022-05-01-at-11.14.51-AM" width="600" height="400" loading="lazy"></figure><p>단항 더하기 연산자(<code>+</code>)는 문자열을 실수로 반환하는 데에도 사용될 수 있습니다.</p><pre><code class="language-js">const quantity = "12.99";
console.log(+quantity);
</code></pre><p></p><figure class="kg-card kg-image-card"><img src="https://www.freecodecamp.org/news/content/images/2022/05/Screen-Shot-2022-05-01-at-11.16.38-AM.png" class="kg-image" alt="Screen-Shot-2022-05-01-at-11.16.38-AM" width="600" height="400" loading="lazy"></figure><p></p><p>문자열이 숫자로 변환될 수 없는 경우에는 <code>NaN</code>을 반환합니다.</p><p></p><pre><code class="language-js">const quantity = "awesome";
console.log(+quantity);
</code></pre><figure class="kg-card kg-image-card"><img src="https://www.freecodecamp.org/news/content/images/2022/05/Screen-Shot-2022-05-01-at-11.18.10-AM.png" class="kg-image" alt="Screen-Shot-2022-05-01-at-11.18.10-AM" width="600" height="400" loading="lazy"></figure><p></p><h2 id="-1-"><b>문자열에 곱하기 1을 하여 문자열을 숫자로 변환하는 방법</b></h2><p><br></p><p>문자열을 숫자로 변환하는 다른 방법으로는 기본 수학 연산을 이용하는 것입니다. 문자열에 1을 곱하면 숫자를 반환받게 됩니다.</p><pre><code class="language-js">const quantity = "12";
console.log(quantity * 1);
</code></pre><p><br></p><figure class="kg-card kg-image-card"><img src="https://www.freecodecamp.org/news/content/images/2022/05/Screen-Shot-2022-05-01-at-11.42.58-AM.png" class="kg-image" alt="Screen-Shot-2022-05-01-at-11.42.58-AM" width="600" height="400" loading="lazy"></figure><p><br></p><p>결과에서 알 수 있듯이 <code>quantity</code> 값에 1을 곱하면 정수 12를 반환합니다. 하지만 어떻게 가능한 것일까요?</p><p></p><p>아래 예제에서 자바스크립트는 문자열 값을 숫자로 변환하고 수학 연산을 수행합니다. 그러나 문자열이 숫자로 변환될 수 없는 경우에는 수학 연산을 하지 않고 <code>NaN</code>을 반환하게 됩니다.</p><p><br></p><figure class="kg-card kg-image-card"><img src="https://www.freecodecamp.org/news/content/images/2022/05/Screen-Shot-2022-05-01-at-11.18.10-AM.png" class="kg-image" alt="Screen-Shot-2022-05-01-at-11.18.10-AM" width="600" height="400" loading="lazy"></figure><p></p><p>이와 같은 방법은 실수에도 똑같이 적용됩니다.</p><pre><code class="language-js">const quantity = "10.5";
console.log(quantity * 1);
</code></pre><p></p><figure class="kg-card kg-image-card"><img src="https://www.freecodecamp.org/news/content/images/2022/05/Screen-Shot-2022-05-01-at-11.56.19-AM.png" class="kg-image" alt="Screen-Shot-2022-05-01-at-11.56.19-AM" width="600" height="400" loading="lazy"></figure><p><br></p><h2 id="-1--1"><b>문자열에 나누기 1을 하여 문자열을 숫자로 변환하는 방법</b></h2><p>곱하기 1을 하는 대신 문자열에 나누기 1을 할 수 있습니다. 자바스크립트는 문자열을 숫자로 변환하여 수학 연산을 수행합니다.</p><pre><code class="language-js">const quantity = "10.5";
console.log(quantity / 1);
</code></pre><p></p><figure class="kg-card kg-image-card"><img src="https://www.freecodecamp.org/news/content/images/2022/05/Screen-Shot-2022-05-01-at-12.08.37-PM.png" class="kg-image" alt="Screen-Shot-2022-05-01-at-12.08.37-PM" width="600" height="400" loading="lazy"></figure><p><br></p><h2 id="-0-"><b>문자열에 빼기 0을 하여 문자열을 숫자로 변환하는 방법</b></h2><p><br>문자열에 0을 빼는 것도 한 가지 방법이 될 수 있습니다. 이전처럼 자바스크립트는 문자열을 숫자로 변환 후 수학 연산을 수행합니다.</p><pre><code class="language-js">const quantity = "19";
console.log(quantity - 0);
</code></pre><p></p><figure class="kg-card kg-image-card"><img src="https://www.freecodecamp.org/news/content/images/2022/05/Screen-Shot-2022-05-01-at-12.11.59-PM.png" class="kg-image" alt="Screen-Shot-2022-05-01-at-12.11.59-PM" width="600" height="400" loading="lazy"></figure><p></p><h2 id="--2"><b>비트 부정 연산자(<code>~</code>)를 이용해 문자열을 숫자로 변환하는 방법</b></h2><p></p><p>비트 부정 연산자(<code>~</code>)는 피연산자의 비트를 뒤집습니다. 그리고 난 후 부호가 있는 32비트 정수로 변환합니다. 부호가 있는 32비트 정수란 32비트(4바이트) 안에서 표현할 수 있는 값을 나타냅니다.</p><p>하나의 비트 부정 연산자(<code>~</code>)를 숫자에 사용하면 -(x + 1) 연산을 실행하게 됩니다.</p><pre><code class="language-js">console.log(~19);
</code></pre><p></p><figure class="kg-card kg-image-card"><img src="https://www.freecodecamp.org/news/content/images/2022/05/Screen-Shot-2022-05-01-at-12.20.18-PM.png" class="kg-image" alt="Screen-Shot-2022-05-01-at-12.20.18-PM" width="600" height="400" loading="lazy"></figure><p></p><p>하지만 두 개의 비트 부정 연산자(<code>~</code>)를 사용하면 문자열을 숫자로 변환합니다.</p><pre><code class="language-js">const quantity = "19";
console.log(~~quantity);
</code></pre><p><br></p><figure class="kg-card kg-image-card"><img src="https://www.freecodecamp.org/news/content/images/2022/05/Screen-Shot-2022-05-01-at-12.28.16-PM.png" class="kg-image" alt="Screen-Shot-2022-05-01-at-12.28.16-PM" width="600" height="400" loading="lazy"></figure><p><br>위와 같은 방법은 실수에는 적용되지 않습니다. 왜냐하면 결괏값으로 정수를 반환하기 때문입니다.</p><pre><code class="language-js">const quantity = "19.99";
console.log(~~quantity);
</code></pre><p><br></p><figure class="kg-card kg-image-card"><img src="https://www.freecodecamp.org/news/content/images/2022/05/Screen-Shot-2022-05-01-at-12.31.16-PM.png" class="kg-image" alt="Screen-Shot-2022-05-01-at-12.31.16-PM" width="600" height="400" loading="lazy"></figure><p><br></p><p>만약 숫자가 아닌 문자에 사용할 경우 0을 반환하게 됩니다.</p><pre><code class="language-js">const quantity = "awesome";
console.log(~~quantity);
</code></pre><p><br></p><figure class="kg-card kg-image-card"><img src="https://www.freecodecamp.org/news/content/images/2022/05/Screen-Shot-2022-05-01-at-12.32.45-PM.png" class="kg-image" alt="Screen-Shot-2022-05-01-at-12.32.45-PM" width="600" height="400" loading="lazy"></figure><p><br>변수의 값이 너무 크면 연산이 실행되지 않는 한계가 있습니다. 그래서 부호가 있는 32비트 정수인지 확인하는 것이 중요합니다.</p><pre><code class="language-js">const quantity = "2700000000";
console.log(~~quantity);
</code></pre><p><br></p><figure class="kg-card kg-image-card"><img src="https://www.freecodecamp.org/news/content/images/2022/05/Screen-Shot-2022-05-01-at-12.36.16-PM.png" class="kg-image" alt="Screen-Shot-2022-05-01-at-12.36.16-PM" width="600" height="400" loading="lazy"></figure><p><br></p><p>이 <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Bitwise_NOT">문서</a> 를 통해 비트 부정 연산자(<code>~</code>)에 대해 더 알아볼 수 있습니다.</p><h2 id="math-floor-"><code>Math.floor()</code> <b>함수를 이용해 문자열을 숫자로 변환하는 방법</b></h2><p><br><code>Math.floor()</code> 함수를 이용해 문자열을 숫자로 변환할 수 있습니다. 이 함수는 값에 버림을 하여 가장 가까운 정수를 반환합니다.</p><p></p><pre><code class="language-js">const quantity = "13.4";
console.log(Math.floor(quantity));
</code></pre><p></p><figure class="kg-card kg-image-card"><img src="https://www.freecodecamp.org/news/content/images/2022/05/Screen-Shot-2022-05-01-at-12.44.53-PM.png" class="kg-image" alt="Screen-Shot-2022-05-01-at-12.44.53-PM" width="600" height="400" loading="lazy"></figure><p><br>앞선 예제들과 같이 숫자가 아닌 문자를 경우 결괏값으로 NaN을 받습니다.</p><p></p><pre><code class="language-js">const quantity = "awesome";
console.log(Math.floor(quantity));
</code></pre><p></p><figure class="kg-card kg-image-card"><img src="https://www.freecodecamp.org/news/content/images/2022/05/Screen-Shot-2022-05-01-at-12.46.08-PM.png" class="kg-image" alt="Screen-Shot-2022-05-01-at-12.46.08-PM" width="600" height="400" loading="lazy"></figure><h2 id="math-ceil-"><code>Math.ceil()</code> <b>함수를 이용해 문자열을 숫자로 변환하는 방법</b></h2><p></p><p><code>Math.ceil()</code> 함수는 숫자를 가장 가까운 정수까지 올림합니다.</p><p></p><pre><code class="language-js">const quantity = "7.18";
console.log(Math.ceil(quantity));
</code></pre><p></p><figure class="kg-card kg-image-card"><img src="https://www.freecodecamp.org/news/content/images/2022/05/Screen-Shot-2022-05-01-at-12.48.15-PM.png" class="kg-image" alt="Screen-Shot-2022-05-01-at-12.48.15-PM" width="600" height="400" loading="lazy"></figure><p></p><h2 id="math-round-"><code>Math.round()</code> <b>함수를 이용해 문자열을 숫자로 변환하는 방법</b></h2><p></p><p><code>Math.round()</code> 함수는 가장 가까운 정수까지 반올림합니다.</p><p></p><p>값이 6.3이면 <code>Math.round()</code>는 6을 반환합니다.</p><p></p><pre><code class="language-js">const quantity = "6.3";
console.log(Math.round(quantity));
</code></pre><p></p><figure class="kg-card kg-image-card"><img src="https://www.freecodecamp.org/news/content/images/2022/05/Screen-Shot-2022-05-01-at-12.50.20-PM.png" class="kg-image" alt="Screen-Shot-2022-05-01-at-12.50.20-PM" width="600" height="400" loading="lazy"></figure><p><br>그러나 값을 6.5로 바꿀 경우에는 함수 <code>Math.round()</code>는 7을 반환합니다.</p><p></p><pre><code class="language-js">const quantity = "6.5";
console.log(Math.round(quantity));
</code></pre><p></p><figure class="kg-card kg-image-card"><img src="https://www.freecodecamp.org/news/content/images/2022/05/Screen-Shot-2022-05-01-at-12.51.35-PM.png" class="kg-image" alt="Screen-Shot-2022-05-01-at-12.51.35-PM" width="600" height="400" loading="lazy"></figure><p><br></p><h1 id="--3"><b>결론</b></h1><p></p><p>이번 글에서는 문자열을 숫자로 변환하는 11가지 방법을 소개해 드렸습니다.</p><p></p><p>윗글에서 언급된 11가지 다른 방법들입니다.</p><p><code>Number()</code> 함수 사용</p><p><code>parseInt()</code> 함수 사용</p><p><code>parseFloat()</code> 함수 사용</p><p>단항 더하기 연산자(<code>+</code>) 사용</p><p>문자열에 곱하기 1</p><p>문자열에 나누기 1</p><p>문자열에 숫자 0을 빼기</p><p>비트 부정 연산자(<code>~</code>) 사용</p><p><code>Math.floor()</code> 함수 사용</p><p><code>Math.ceil()</code> 함수 사용</p><p><code>Math.round()</code> 함수 사용</p><p></p><p>이 글을 재밌게 읽어주셨길 바라며 여러분의 자바스크립트 여정에 행운이 가득하길 희망합니다.</p> ]]>
                </content:encoded>
            </item>
        
    </channel>
</rss>
