<?xml version="1.0" encoding="utf-8"?><feed xmlns="http://www.w3.org/2005/Atom" xml:lang="ko-KR, en-US"><generator uri="https://jekyllrb.com/" version="3.9.2">Jekyll</generator><link href="https://lunadein2022.github.io/feed.xml" rel="self" type="application/atom+xml" /><link href="https://lunadein2022.github.io/" rel="alternate" type="text/html" hreflang="ko-KR, en-US" /><updated>2023-01-21T21:50:25+09:00</updated><id>https://lunadein2022.github.io/feed.xml</id><title type="html">JawsBean</title><subtitle>Smile the Door!
</subtitle><author><name>Subin Cho</name><email>lunadein2022@gmail.com</email></author><entry><title type="html">[JS] 클로저 모듈 패턴</title><link href="https://lunadein2022.github.io/study/basic2-2-1.html" rel="alternate" type="text/html" title="[JS] 클로저 모듈 패턴" /><published>2023-01-19T00:00:00+09:00</published><updated>2023-01-19T00:00:00+09:00</updated><id>https://lunadein2022.github.io/study/basic2-2-1</id><content type="html" xml:base="https://lunadein2022.github.io/study/basic2-2-1.html">&lt;ul id=&quot;markdown-toc&quot;&gt;
  &lt;li&gt;&lt;a href=&quot;#클로저-모듈-패턴&quot; id=&quot;markdown-toc-클로저-모듈-패턴&quot;&gt;클로저 모듈 패턴&lt;/a&gt;    &lt;ul&gt;
      &lt;li&gt;&lt;a href=&quot;#클로저를-이용해-새로운-객체-생성&quot; id=&quot;markdown-toc-클로저를-이용해-새로운-객체-생성&quot;&gt;클로저를 이용해 새로운 객체 생성&lt;/a&gt;&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;!--more--&gt;

&lt;blockquote&gt;
  &lt;p&gt;객체 지향 프로그래밍은, 절차 지향 프로그래밍과는 다르게 데이터와 기능을 한 곳에 묶어서 처리한다.&lt;br /&gt;
속성과 메서드가 하나의 “객체”라는 개념에 포함되며, 이는 자바스크립트 내장 타입인 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;object&lt;/code&gt;와는 다르게, 클래스(Class)라는 이름으로 부른다.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2 id=&quot;클로저-모듈-패턴&quot;&gt;클로저 모듈 패턴&lt;/h2&gt;

&lt;p&gt;메서드 호출은 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;객체.메서드()&lt;/code&gt;와 같이 객체 내에 메서드를 호출하는 방법이다.&lt;br /&gt;
&lt;span style=&quot;color: tomato&quot;&gt;메서드 호출 방식을 이용할 때에는 ==화살표 함수==를 쓰지 않는다.&lt;/span&gt;&lt;/p&gt;

&lt;div class=&quot;language-javascript highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kd&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;counter1&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;na&quot;&gt;value&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
  &lt;span class=&quot;na&quot;&gt;increase&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;function&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;value&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;++&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;// 메서드 호출을 할 경우, this는 counter1을 가리킵니다&lt;/span&gt;
  &lt;span class=&quot;p&quot;&gt;},&lt;/span&gt;
  &lt;span class=&quot;na&quot;&gt;decrease&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;function&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;value&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;--&lt;/span&gt;
  &lt;span class=&quot;p&quot;&gt;},&lt;/span&gt;
  &lt;span class=&quot;na&quot;&gt;getValue&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;function&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;value&lt;/span&gt;
  &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;nx&quot;&gt;counter1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;increase&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
&lt;span class=&quot;nx&quot;&gt;counter1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;increase&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
&lt;span class=&quot;nx&quot;&gt;counter1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;increase&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
&lt;span class=&quot;nx&quot;&gt;counter1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;decrease&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
&lt;span class=&quot;nx&quot;&gt;counter1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;getValue&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;// 2&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;클로저를-이용해-새로운-객체-생성&quot;&gt;클로저를 이용해 새로운 객체 생성&lt;/h3&gt;
&lt;p&gt;똑같은 기능을 하는 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;counter&lt;/code&gt;함수가 여러 개 필요할 떄, 같은 코드를 여러 번 복사, 붙여넣기 하는건 비효율적이다.&lt;br /&gt;
아래 코드는 똑같은 기능을 하는 카운터를 여러 개 만드는 방법 중 하나인 ==클로저 모듈 패턴==이다.&lt;/p&gt;

&lt;div class=&quot;language-javascript highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kd&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;makeCounter&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;kd&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;value&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;na&quot;&gt;increase&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;function&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
      &lt;span class=&quot;nx&quot;&gt;value&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;++&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;},&lt;/span&gt;
    &lt;span class=&quot;na&quot;&gt;decrease&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;function&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
      &lt;span class=&quot;nx&quot;&gt;value&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;--&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;},&lt;/span&gt;
    &lt;span class=&quot;na&quot;&gt;getValue&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;function&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
      &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;value&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
  &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;kd&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;counter1&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;makeCounter&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
&lt;span class=&quot;nx&quot;&gt;counter1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;increase&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
&lt;span class=&quot;nx&quot;&gt;counter1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;getValue&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;// 1&lt;/span&gt;

&lt;span class=&quot;kd&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;counter2&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;makeCounter&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
&lt;span class=&quot;nx&quot;&gt;counter2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;decrease&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
&lt;span class=&quot;nx&quot;&gt;counter2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;decrease&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
&lt;span class=&quot;nx&quot;&gt;counter2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;getValue&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;// -2&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;</content><author><name>Subin Cho</name><email>lunadein2022@gmail.com</email></author><category term="Study" /><category term="study" /><category term="javascript" /><summary type="html"></summary><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://lunadein2022.github.io/assets/img/thumbnail/js.png" /><media:content medium="image" url="https://lunadein2022.github.io/assets/img/thumbnail/js.png" xmlns:media="http://search.yahoo.com/mrss/" /></entry><entry><title type="html">[JS] 클래스와 인스턴스</title><link href="https://lunadein2022.github.io/study/basic2-2-2.html" rel="alternate" type="text/html" title="[JS] 클래스와 인스턴스" /><published>2023-01-19T00:00:00+09:00</published><updated>2023-01-19T00:00:00+09:00</updated><id>https://lunadein2022.github.io/study/basic2-2-2</id><content type="html" xml:base="https://lunadein2022.github.io/study/basic2-2-2.html">&lt;ul id=&quot;markdown-toc&quot;&gt;
  &lt;li&gt;&lt;a href=&quot;#객체-지향-프로그래밍&quot; id=&quot;markdown-toc-객체-지향-프로그래밍&quot;&gt;객체 지향 프로그래밍&lt;/a&gt;    &lt;ul&gt;
      &lt;li&gt;&lt;a href=&quot;#instance-만들기&quot; id=&quot;markdown-toc-instance-만들기&quot;&gt;instance 만들기&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;#class-만들기&quot; id=&quot;markdown-toc-class-만들기&quot;&gt;class 만들기&lt;/a&gt;        &lt;ul&gt;
          &lt;li&gt;&lt;a href=&quot;#es5&quot; id=&quot;markdown-toc-es5&quot;&gt;ES5&lt;/a&gt;&lt;/li&gt;
          &lt;li&gt;&lt;a href=&quot;#es6&quot; id=&quot;markdown-toc-es6&quot;&gt;ES6&lt;/a&gt;&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#속성과-메서드&quot; id=&quot;markdown-toc-속성과-메서드&quot;&gt;속성과 메서드&lt;/a&gt;    &lt;ul&gt;
      &lt;li&gt;&lt;a href=&quot;#속성-this&quot; id=&quot;markdown-toc-속성-this&quot;&gt;속성? this?&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;#메서드&quot; id=&quot;markdown-toc-메서드&quot;&gt;메서드?&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;#instance에서-사용하는-법&quot; id=&quot;markdown-toc-instance에서-사용하는-법&quot;&gt;Instance에서 사용하는 법&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;#prototype-constructor-this&quot; id=&quot;markdown-toc-prototype-constructor-this&quot;&gt;prototype? constructor? this?&lt;/a&gt;&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#중요하니-외우자&quot; id=&quot;markdown-toc-중요하니-외우자&quot;&gt;중요하니 외우자&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;!--more--&gt;

&lt;blockquote&gt;
  &lt;p&gt;객체 지향 프로그래밍은, 절차 지향 프로그래밍과는 다르게 데이터와 기능을 한 곳에 묶어서 처리한다.&lt;br /&gt;
속성과 메서드가 하나의 “객체”라는 개념에 포함되며, 이는 자바스크립트 내장 타입인 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;object&lt;/code&gt;와는 다르게, 클래스(Class)라는 이름으로 부른다.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2 id=&quot;객체-지향-프로그래밍&quot;&gt;객체 지향 프로그래밍&lt;/h2&gt;
&lt;p&gt;객체 지향 프로그래밍은&lt;br /&gt;
하나의 ==모델이 되는 청사진==을 만들고 &lt;span style=&quot;color: tomato; font-size: 1.2rem&quot;&gt;class&lt;/span&gt;&lt;br /&gt;
그 ==청사진을 바탕으로 한 객체==를 만드는&lt;span style=&quot;color: tomato; font-size: 1.2rem&quot;&gt;instance&lt;/span&gt;&lt;br /&gt;
==프로그래밍 패턴==&lt;/p&gt;

&lt;p class=&quot;figcaption&quot;&gt;&lt;img src=&quot;/assets/img/2023-01-19/class.png&quot; alt=&quot;class&quot; /&gt;&lt;br /&gt;
기본적인 설계로 자동차의 청사진을 그려놓기. -&amp;gt; 청사진을 바탕으로 각각의 객체가 특정한 자동차 모델로 만들어짐&lt;/p&gt;

&lt;h3 id=&quot;instance-만들기&quot;&gt;instance 만들기&lt;/h3&gt;
&lt;p&gt;instance는 그냥 일반적인 함수를 정의하듯 만든다.&lt;br /&gt;
근데 함수를 이용하는 방법이 조금 다르다.&lt;br /&gt;
==&lt;span style=&quot;font-size: 1.2rem&quot;&gt;new&lt;/span&gt;==키워드를 사용해 만든다.&lt;/p&gt;

&lt;div class=&quot;language-javascript highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kd&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;avante&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;Car&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;hyundai&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;avante&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;black&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;kd&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;mini&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;Car&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;bmw&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;ini&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;white&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;kd&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;beetles&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;Car&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;volkswagen&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;beetles&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;red&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;//각각의 인스턴스는 'Car'라는 클래스의 고유한 속성과, 메소드를 갖는다.&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;class-만들기&quot;&gt;class 만들기&lt;/h3&gt;
&lt;h4 id=&quot;es5&quot;&gt;ES5&lt;/h4&gt;
&lt;p&gt;==&lt;span style=&quot;font-size: 1.2rem&quot;&gt;대문자&lt;/span&gt;==로 시작하며 ==&lt;span style=&quot;font-size: 1.2rem&quot;&gt;일반명사&lt;/span&gt;==로 만든다.&lt;br /&gt;
(일반 함수는 적절한 동사를 포함하고 소문자로 시작하는 것과는 대조적이다.)&lt;/p&gt;

&lt;h4 id=&quot;es6&quot;&gt;ES6&lt;/h4&gt;
&lt;p&gt;신문법 ES6에 새로운 방법이 도입되었는데 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;class&lt;/code&gt;키워드이다.&lt;br /&gt;
최근엔 이 방법이 자주 쓰인다고 한다.&lt;/p&gt;

&lt;p&gt;ES5와 ES6의 차이를 아래 코드로 알아보면&lt;/p&gt;

&lt;div class=&quot;language-javascript highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;c1&quot;&gt;//ES5&lt;/span&gt;
&lt;span class=&quot;kd&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;Car&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;brand&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;color&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;){&lt;/span&gt;
  &lt;span class=&quot;c1&quot;&gt;//인스턴스가 만들어질 때 실행되는 코드&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;c1&quot;&gt;//ES6&lt;/span&gt;
&lt;span class=&quot;kd&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;Car&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;kd&quot;&gt;constructor&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;brand&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;color&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;){&lt;/span&gt;
    &lt;span class=&quot;c1&quot;&gt;//인스턴스가 만들어질 때 실행되는 코드&lt;/span&gt;
  &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;위에서 보이는 함수는 객체지향 프로그래밍에서 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;생성자(constructor)함수&lt;/code&gt;라고 한다.&lt;br /&gt;
생성자 함수는 return 값을 만들지 않는다.&lt;/p&gt;

&lt;h2 id=&quot;속성과-메서드&quot;&gt;속성과 메서드&lt;/h2&gt;
&lt;p&gt;클래스에 속성과 메소드를 정의하고, 인스턴스에서 이용한다.&lt;/p&gt;

&lt;p&gt;? 자동차로 속성과 메서드를 생각해보면&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;속성: 브랜드, 차 이름, 색상, 현재 연료 상태, 최고 속력 , 옵션 등&lt;/li&gt;
  &lt;li&gt;메서드: (객체에 딸린 함수) 연료 주입, 속력 설정, 운전 등&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;img src=&quot;/assets/img/2023-01-19/class2.png&quot; alt=&quot;class2&quot; /&gt;&lt;/p&gt;

&lt;h3 id=&quot;속성-this&quot;&gt;속성? this?&lt;/h3&gt;
&lt;p&gt;객체 지향 프로그래밍에서 빠지지 않고 등장하는 키워드 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;this&lt;/code&gt;.&lt;br /&gt;
==인스턴스 객체==를 의미한다.&lt;/p&gt;

&lt;div class=&quot;language-javascript highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;c1&quot;&gt;//ES5&lt;/span&gt;
&lt;span class=&quot;kd&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;Car&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;brand&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;color&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;){&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;brand&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;brand&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;name&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;color&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;color&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;c1&quot;&gt;//ES6&lt;/span&gt;
&lt;span class=&quot;kd&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;Car&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;kd&quot;&gt;constructor&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;brand&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;color&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;){&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;brand&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;brand&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;name&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;color&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;color&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;parameter&lt;/code&gt;로 넘어온 브랜드, 이름, 색상 등은 인스턴스 생성 시 지정하는 값이며,&lt;br /&gt;
&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;this&lt;/code&gt;에 할당한다는 것은 =&amp;gt; 만들어진 인스턴스에 해당 브랜드, 이름, 색상을 부여하겠다는 의미.&lt;/p&gt;

&lt;h3 id=&quot;메서드&quot;&gt;메서드?&lt;/h3&gt;

&lt;div class=&quot;language-javascript highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;c1&quot;&gt;//ES5&lt;/span&gt;
&lt;span class=&quot;kd&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;Car&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;brand&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;color&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;){&lt;/span&gt;
  &lt;span class=&quot;nx&quot;&gt;Car&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;prototype&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;refuel&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;function&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(){&lt;/span&gt;
    &lt;span class=&quot;c1&quot;&gt;//연료 공급을 구현하는 코드&lt;/span&gt;
  &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
  &lt;span class=&quot;nx&quot;&gt;Car&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;prototype&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;drive&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;function&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(){&lt;/span&gt;
    &lt;span class=&quot;c1&quot;&gt;//운전을 구현하는 코드&lt;/span&gt;
  &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;ES5는 prototype이라는 키워드를 사용해야 메서드를 정의할 수 있다.&lt;br /&gt;
Car 클래스에 메서드를 추가하기 위해서 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Car.prototype.fuel&lt;/code&gt;같이 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;prototype&lt;/code&gt;을 이용해야 함.&lt;/p&gt;

&lt;div class=&quot;language-javascript highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kd&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;Car&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;kd&quot;&gt;constructor&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;brand&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;color&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;){&lt;/span&gt;&lt;span class=&quot;cm&quot;&gt;/* 생략 */&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;

  &lt;span class=&quot;nx&quot;&gt;refuel&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(){&lt;/span&gt;

  &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;

  &lt;span class=&quot;nx&quot;&gt;drive&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(){&lt;/span&gt;

  &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;ES6는 생성자 함수와 함께 class 키워드 안쪽에 묶어서 정의한다.&lt;br /&gt;
&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;refule(){}&lt;/code&gt;,&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;drive(){}&lt;/code&gt;와 같이 작성되어 있는 부분을 말한다.&lt;/p&gt;

&lt;h3 id=&quot;instance에서-사용하는-법&quot;&gt;Instance에서 사용하는 법&lt;/h3&gt;

&lt;div class=&quot;language-javascript highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kd&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;avante&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;Car&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;hyundai&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;avante&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;black&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;nx&quot;&gt;avante&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;color&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;// 'black'&lt;/span&gt;
&lt;span class=&quot;nx&quot;&gt;avante&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;drive&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;();&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;//아반떼가 운전을 시작합니다.&lt;/span&gt;

&lt;span class=&quot;kd&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;mini&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;Car&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;bmw&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;nmini&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;white&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;nx&quot;&gt;mini&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;brand&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;// 'bmw'&lt;/span&gt;
&lt;span class=&quot;nx&quot;&gt;mini&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;refuel&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;();&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;//미니에 연료를 공급합니다.&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;prototype-constructor-this&quot;&gt;prototype? constructor? this?&lt;/h3&gt;
&lt;p class=&quot;figcaption&quot;&gt;|용어|용어설명|
|—-|—–|
|prototype|모델의 청사진을 만들 때 쓰는 원형 객체(original form)이다|
|constructor|인스턴스가 초기화될 때 실행하는 ==생성자== 함수|
|this|함수가 실행될 때, 해당 scope마다 생성되는 고유한 실행 context. ==new==키워드로 인스턴스를 생성했을 땐, 해당 인스턴스가 바로 this의 값이 된다.|
JavaScript에만 유효한 용어이다. 하지만 중요하다.&lt;/p&gt;

&lt;h2 id=&quot;중요하니-외우자&quot;&gt;중요하니 외우자&lt;/h2&gt;

&lt;p class=&quot;figcaption&quot;&gt;&lt;img src=&quot;/assets/img/2023-01-19/class3.png&quot; alt=&quot;class3&quot; /&gt;
ES5방식이고 현재는 신문법이 더 잘 쓰이므로 신문법도 잘 외워두자.&lt;/p&gt;

&lt;div class=&quot;language-javascript highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kd&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;Car&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;kd&quot;&gt;constructor&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;brand&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;color&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;){&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;brand&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;brand&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;name&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;color&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;color&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
  &lt;span class=&quot;nx&quot;&gt;drive&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(){&lt;/span&gt;
    &lt;span class=&quot;nx&quot;&gt;console&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;name&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;가 운전을 시작합니다&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
  &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;kd&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;avante&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;Car&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;hyundai&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;avante&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;black&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;nx&quot;&gt;avante&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;color&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;//'black'&lt;/span&gt;
&lt;span class=&quot;nx&quot;&gt;avante&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;drive&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;();&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;// 'avante'가 운전을 시작합니다.&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;details&gt;
&lt;summary style=&quot;color: tomato; font-size: 1.2rem&quot;&gt;배열은 Array의 인스턴스다?&lt;/summary&gt;
&lt;div&gt;

    &lt;div class=&quot;language-javascript highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kd&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;avante&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;Car&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;hyundai&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;avante&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;black&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;nx&quot;&gt;avante&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;color&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;//'black'&lt;/span&gt;
&lt;span class=&quot;nx&quot;&gt;avante&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;drive&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;();&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;//아반떼가 운전을 시작합니다.&lt;/span&gt;

&lt;span class=&quot;kd&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;arr&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;hi&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;my&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;];&lt;/span&gt;
&lt;span class=&quot;nx&quot;&gt;arr&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;length&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;//3&lt;/span&gt;
&lt;span class=&quot;nx&quot;&gt;arr&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;push&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;is&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;// ['hi', 'my', 'name', 'is']&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;    &lt;/div&gt;

    &lt;p&gt;배열은 전부 Array의 인스턴스이다!!!!&lt;br /&gt;
속성, 메서드 사용법이 동일하다!!&lt;/p&gt;

    &lt;p&gt;&lt;span style=&quot;color: royalblue; font-size: 1.2rem&quot;&gt;new Array(__, __, __)&lt;/span&gt;&lt;/p&gt;

    &lt;p&gt;와 같은 방식으로도 배열을 만들 수 있다!&lt;/p&gt;

    &lt;p&gt;==배열을 정의한다 === Array의 인스턴스를 만들어낸다==&lt;/p&gt;

    &lt;p&gt;(mdn 메서드 설명에 prototype이라고 붙어있는 이유는 모든 메서드들이 클래스의 원형 객체에 정의되어 있기 때문이다.)&lt;/p&gt;

  &lt;/div&gt;
&lt;/details&gt;</content><author><name>Subin Cho</name><email>lunadein2022@gmail.com</email></author><category term="Study" /><category term="study" /><category term="javascript" /><summary type="html"></summary><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://lunadein2022.github.io/assets/img/thumbnail/js.png" /><media:content medium="image" url="https://lunadein2022.github.io/assets/img/thumbnail/js.png" xmlns:media="http://search.yahoo.com/mrss/" /></entry><entry><title type="html">[JS] 객체 지향 프로그래밍 OOP</title><link href="https://lunadein2022.github.io/study/basic2-2-3.html" rel="alternate" type="text/html" title="[JS] 객체 지향 프로그래밍 OOP" /><published>2023-01-19T00:00:00+09:00</published><updated>2023-01-19T00:00:00+09:00</updated><id>https://lunadein2022.github.io/study/basic2-2-3</id><content type="html" xml:base="https://lunadein2022.github.io/study/basic2-2-3.html">&lt;ul id=&quot;markdown-toc&quot;&gt;
  &lt;li&gt;&lt;a href=&quot;#절차적-언어&quot; id=&quot;markdown-toc-절차적-언어&quot;&gt;절차적 언어&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#객체-지향-언어&quot; id=&quot;markdown-toc-객체-지향-언어&quot;&gt;객체 지향 언어&lt;/a&gt;    &lt;ul&gt;
      &lt;li&gt;&lt;a href=&quot;#oop&quot; id=&quot;markdown-toc-oop&quot;&gt;OOP&lt;/a&gt;&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;!--more--&gt;

&lt;blockquote&gt;
  &lt;p&gt;객체 지향 프로그래밍은, 절차 지향 프로그래밍과는 다르게 데이터와 기능을 한 곳에 묶어서 처리한다.&lt;br /&gt;
속성과 메서드가 하나의 “객체”라는 개념에 포함되며, 이는 자바스크립트 내장 타입인 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;object&lt;/code&gt;와는 다르게, 클래스(Class)라는 이름으로 부른다.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h1 id=&quot;절차적-언어&quot;&gt;절차적 언어&lt;/h1&gt;

&lt;p&gt;옛날 옛적엔 프로그래밍언어를 보통 ‘절차적 언어’라고 불렀다. (C, 포트란 등이 있다고 한다)&lt;br /&gt;
절차적 언어란 무엇이냐, ‘절차대로 합시다!‘ 에서 풍기는 뉘앙스처럼 순서대로,&lt;/p&gt;

&lt;p&gt;순차적으로 명령들을 처리하는 언어를 말한다.&lt;/p&gt;

&lt;p&gt;근데 이게 생각보다 불편한거다.&lt;br /&gt;
왜? 순서가 지나가면 그대로 끝인거니까..!&lt;br /&gt;
예전에 학교에서 급식먹다보면 맛있는 반찬은 더 먹고 싶을 때가 있지 않은가?&lt;br /&gt;
하지만 그렇다고 해서 중간에 끼어서 반찬을 더 달라고 했다간 뒤에서 차례를 기다리며 쏘아보는 학우들의 눈빛레이저에 타버리고 말 것이다.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/img/2023-01-19/oop.png&quot; alt=&quot;oop&quot; /&gt;&lt;/p&gt;

&lt;h1 id=&quot;객체-지향-언어&quot;&gt;객체 지향 언어&lt;/h1&gt;
&lt;p&gt;그래서 등장한 것이 바로 이 객체 지향 언어이다.&lt;br /&gt;
물론 순차적으로 작동은 한다. 하나의 커다란 대 전제인 것이다.&lt;br /&gt;
하지만 그 안에서 데이터의 접근, 처리과정에 대한 것들이 각각 그룹을 만들어 보다 효율적으로 데이터를 처리할 수 있게 된 것이다.&lt;/p&gt;

&lt;p&gt;이렇게 생각하면 어떨까?&lt;br /&gt;
우리가 레고를 만든다고 생각해보자.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/img/2023-01-19/oop2.jpeg&quot; alt=&quot;oop2&quot; /&gt;&lt;/p&gt;

&lt;p&gt;당신은 집을 만들 것이고 나는 자동차를 만들거다.&lt;br /&gt;
함께 레고들을 모두 가운데에 쏟아놓고 이제 레고를 만드는데…. &amp;lt;-이러면 진행속도도 더디고 아무거나 갖다쓰다가 뒤늦게 다시 부품을 찾고.. 이런 일이 반복될 것이다.&lt;/p&gt;

&lt;p&gt;하지만, 각자의 레고를 서로에게서 분리하고, 그 안에서 색깔대로, 모양대로 모아 레고를 만든다면? 비록 분류과정에서 시간이 조금 걸릴지 몰라도 실제로 조립을 시작하면 금방 완성될 것이다!&lt;/p&gt;

&lt;p&gt;이러한 개념의 객체 지향 언어는 ‘클래스’라고 부르는 데이터 모델의 청사진을 사용해 코드를 작성하는 특징이 있고,&lt;br /&gt;
현대의 언어들은 대부분 객체 지향의 특징을 가지고 있다. (Java, C++, C#..등등..)&lt;br /&gt;
(그러나 자바스크립트는 엄말히 말해 객체 지향 언어는 아니다. 하지만 객체 지향 패턴으로 작성할 수는 있지.)&lt;/p&gt;

&lt;h2 id=&quot;oop&quot;&gt;OOP&lt;/h2&gt;
&lt;ol&gt;
  &lt;li&gt;OOP는 프로그램 설계철학이다.&lt;/li&gt;
  &lt;li&gt;OOP의 모든 것은 “객체”로 그룹화된다.&lt;/li&gt;
  &lt;li&gt;OOP의 4가지 주요 개념을 통해 재사용성을 얻을 수 있다.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;객체 내에는 ==데이터와 기능이 함께 있다==라는 원칙에 따라 메서드와 속성이 존재한다.&lt;/p&gt;</content><author><name>Subin Cho</name><email>lunadein2022@gmail.com</email></author><category term="Study" /><category term="study" /><category term="javascript" /><summary type="html"></summary><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://lunadein2022.github.io/assets/img/thumbnail/js.png" /><media:content medium="image" url="https://lunadein2022.github.io/assets/img/thumbnail/js.png" xmlns:media="http://search.yahoo.com/mrss/" /></entry><entry><title type="html">[JS/브라우저] DOM</title><link href="https://lunadein2022.github.io/study/basic1-10-1.html" rel="alternate" type="text/html" title="[JS/브라우저] DOM" /><published>2023-01-18T00:00:00+09:00</published><updated>2023-01-18T00:00:00+09:00</updated><id>https://lunadein2022.github.io/study/basic1-10-1</id><content type="html" xml:base="https://lunadein2022.github.io/study/basic1-10-1.html">&lt;ul id=&quot;markdown-toc&quot;&gt;
  &lt;li&gt;&lt;a href=&quot;#html에-javascript-적용하기&quot; id=&quot;markdown-toc-html에-javascript-적용하기&quot;&gt;HTML에 JavaScript 적용하기&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#dom-다루기&quot; id=&quot;markdown-toc-dom-다루기&quot;&gt;DOM 다루기&lt;/a&gt;    &lt;ul&gt;
      &lt;li&gt;&lt;a href=&quot;#create&quot; id=&quot;markdown-toc-create&quot;&gt;CREATE&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;#append&quot; id=&quot;markdown-toc-append&quot;&gt;APPEND&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;#read&quot; id=&quot;markdown-toc-read&quot;&gt;READ&lt;/a&gt;        &lt;ul&gt;
          &lt;li&gt;&lt;a href=&quot;#tweetdiv를-container에-추가하기&quot; id=&quot;markdown-toc-tweetdiv를-container에-추가하기&quot;&gt;tweetDiv를 container에 추가하기&lt;/a&gt;&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;#update&quot; id=&quot;markdown-toc-update&quot;&gt;UPDATE&lt;/a&gt;        &lt;ul&gt;
          &lt;li&gt;&lt;a href=&quot;#1-비어있는-엘리먼트에-문자열-추가하기&quot; id=&quot;markdown-toc-1-비어있는-엘리먼트에-문자열-추가하기&quot;&gt;1. 비어있는 엘리먼트에 문자열 추가하기&lt;/a&gt;&lt;/li&gt;
          &lt;li&gt;&lt;a href=&quot;#2-엘리먼트에-class-추가하기&quot; id=&quot;markdown-toc-2-엘리먼트에-class-추가하기&quot;&gt;2. 엘리먼트에 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;class&lt;/code&gt; 추가하기&lt;/a&gt;&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;#delete&quot; id=&quot;markdown-toc-delete&quot;&gt;DELETE&lt;/a&gt;        &lt;ul&gt;
          &lt;li&gt;&lt;a href=&quot;#1-삭제하려는-요소의-위치를-알고-있는-경우&quot; id=&quot;markdown-toc-1-삭제하려는-요소의-위치를-알고-있는-경우&quot;&gt;1. 삭제하려는 요소의 위치를 알고 있는 경우&lt;/a&gt;&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;#2-여러-개의-자식-요소를-지우고-싶다면&quot; id=&quot;markdown-toc-2-여러-개의-자식-요소를-지우고-싶다면&quot;&gt;2. 여러 개의 자식 요소를 지우고 싶다면&lt;/a&gt;&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;!--more--&gt;

&lt;h3 id=&quot;html에-javascript-적용하기&quot;&gt;HTML에 JavaScript 적용하기&lt;/h3&gt;

&lt;p&gt;HTML에 JavaScript를 적용하려면 &lt;scritp&gt;&lt;/scritp&gt;태그를 이용한다.&lt;br /&gt;
웹 브라우저가 작성된 코드를 해석하다 스크립트 태그를 만나면 HTML코드 해석을 멈추고 스크립트 태그를 먼저 실행한다. (등장과 함께)&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/img/2023-01-18/script.png&quot; alt=&quot;script&quot; /&gt;&lt;/p&gt;

&lt;p&gt;**이 떄, 스크립트 요소를 HTML에 추가하는 두 가지 방법이 있다.&lt;/p&gt;
&lt;ol&gt;
  &lt;li&gt;
    &lt;head&gt;&lt;/head&gt;
    &lt;p&gt;에 추가하기&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;&amp;lt;/body&amp;gt;가 끝나기 전에 추가하기.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;//* 왜 인지 추가하기&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;span style=&quot;color: tomato; font-size: 1.2rem&quot;&gt;자바스크립트라는 프로그래밍 언어와 DOM을 이용해 HTML에 접근하고 조작한다.&lt;/span&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;h2 id=&quot;dom-다루기&quot;&gt;DOM 다루기&lt;/h2&gt;

&lt;details&gt;
&lt;summary style=&quot;color: tomato; font-size: 1.2rem&quot;&gt;Tip&lt;/summary&gt;
&lt;div&gt;

    &lt;ul&gt;
      &lt;li&gt;DOM구조를 조회할 때에는 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;console.dir&lt;/code&gt;이 유용하다
&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;console.dir&lt;/code&gt;은 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;console.log&lt;/code&gt;와 달리 DOM을 객체의 모습으로 출력한다.&lt;/li&gt;
    &lt;/ul&gt;

  &lt;/div&gt;
&lt;/details&gt;

&lt;p&gt;아래의 이미지처럼 Tweetlist를 만들어보았다.&lt;br /&gt;
요소를 만들고, 추가하고, 수정하고, 삭제해볼 것이다.&lt;br /&gt;
&lt;img src=&quot;/assets/img/2023-01-18/tweetlist.png&quot; alt=&quot;tweetlist&quot; /&gt;&lt;/p&gt;

&lt;h3 id=&quot;create&quot;&gt;CREATE&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;&lt;span style=&quot;color: tomato; font-size: 1.2rem&quot;&gt;document.createElement(‘div’)&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;
= 새로운 ‘div’요소를 만든다&lt;/p&gt;

&lt;div class=&quot;language-javascript highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nb&quot;&gt;document&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;createElement&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;div&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;//'div'요소를 만들었다&lt;/span&gt;

&lt;span class=&quot;kd&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;tweetDiv&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;document&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;createElement&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;div&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;//'div'요소를 만들어 'twetDiv'에 할당했다.&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;&lt;img src=&quot;/assets/img/2023-01-18/create.png&quot; alt=&quot;create&quot; /&gt;&lt;/p&gt;

&lt;p&gt;‘div’요소를 만들었다. 그러나 Tweetlist에는 보이지 않을 것이다. 왜냐하면 요소에 추가하지 않았기 때문이다.&lt;/p&gt;

&lt;h3 id=&quot;append&quot;&gt;APPEND&lt;/h3&gt;
&lt;p&gt;create에서 생성한 twwetDiv라는 변수는 아직 &lt;strong&gt;공중에 붕 뜬 상태&lt;/strong&gt;다.
그러므로 create에서 생성한 tweetDiv를 트리구조와 연결한다. -&amp;gt; Tweetlist에 append한다.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;span style=&quot;color: tomato; font-size: 1.2rem&quot;&gt;document.body.append(tweetDiv)&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;
= &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;tweetDiv&lt;/code&gt;에 담긴 새로운 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;&amp;lt;div&amp;gt;&lt;/code&gt;요소를 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;&amp;lt;body&amp;gt;&lt;/code&gt;요소에 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;append&lt;/code&gt;한다.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/img/2023-01-18/append.png&quot; alt=&quot;append&quot; /&gt;&lt;/p&gt;

&lt;p&gt;‘tweetDiv’에 담긴 ‘div’요소를 ‘body’요소에 append했다. 그러나 아직 Tweetlist에는 보이지 않을 것이다. 왜냐하면 추가된 요소에 내용이 작성되어 있지 않기 때문이다.&lt;/p&gt;

&lt;p&gt;그런데 뭔가 거슬린다. 왜 새로 만든 ‘div’요소는 ‘#container’에 들어가 있지 않을까? 넣으려면 어떻게 해야할까?&lt;/p&gt;

&lt;h3 id=&quot;read&quot;&gt;READ&lt;/h3&gt;
&lt;p&gt;DOM을 이용해 HTML Element를 조회하는 방법이다.&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;클래스 이름&lt;/strong&gt;이 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;tweet&lt;/code&gt;인 HTML 엘리먼트 중 첫 번째 엘리먼트를 조회한다.
&lt;strong&gt;&lt;span style=&quot;color: tomato; font-size: 1.2rem&quot;&gt;querySelector&lt;/span&gt;&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;language-javascript highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kd&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;oneTweet&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;document&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;querySelector&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;.tweet&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;클래스 이름&lt;/strong&gt;이 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;tweet&lt;/code&gt;인 HTML 엘리먼트 전부를 조회한다.
&lt;strong&gt;&lt;span style=&quot;color: tomato; font-size: 1.2rem&quot;&gt;querySelectorAll&lt;/span&gt;&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;details&gt;
&lt;summary style=&quot;color: tomato&quot;&gt;그리고&lt;/summary&gt;
&lt;div&gt;

    &lt;p&gt;이렇게 조회한 HTML요소들은 배열처럼 ‘for’문을 사용할 수 있다. (배열은 아님)&lt;br /&gt;
이런 배열 아닌 배열을 ‘유사배열’, ‘배열형 객체’ 등 다양하게 부른다.&lt;br /&gt;
정식 명칭은 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Array-like Object&lt;/code&gt;이다.&lt;/p&gt;

  &lt;/div&gt;
&lt;/details&gt;

&lt;div class=&quot;language-javascript highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kd&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;tweets&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;document&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;querySelectorAll&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;.tweet&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;details&gt;
&lt;summary style=&quot;color: tomato&quot;&gt;+옛날방식인 getElementById&lt;/summary&gt;
&lt;div&gt;

    &lt;p&gt;DOM조회 메서드인 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;getElementById&lt;/code&gt;는 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;querySelector&lt;/code&gt;와 비슷한 역할을 하는 오래된 방식이다.&lt;/p&gt;

    &lt;div class=&quot;language-javascript highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kd&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;getOneTweet&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;document&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;getElementById&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;container&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;kd&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;queryOneTweet&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;document&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;querySelector&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;#container&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;nx&quot;&gt;console&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;getOneTweet&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;===&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;queryOneTweet&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;// true&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;    &lt;/div&gt;

  &lt;/div&gt;
&lt;/details&gt;

&lt;h4 id=&quot;tweetdiv를-container에-추가하기&quot;&gt;tweetDiv를 container에 추가하기&lt;/h4&gt;

&lt;div class=&quot;language-javascript highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kd&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;container&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;document&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;querySelector&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;#container&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;kd&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;tweetDiv&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;document&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;createElement&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;div&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;nx&quot;&gt;container&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;append&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;tweetDiv&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;&lt;img src=&quot;/assets/img/2023-01-18/read.png&quot; alt=&quot;read&quot; /&gt;&lt;br /&gt;
&lt;img src=&quot;/assets/img/2023-01-18/read2.png&quot; alt=&quot;read2&quot; /&gt;)&lt;/p&gt;

&lt;p&gt;각각 변수에 담아 append해주면 된다.&lt;br /&gt;
내용을 추가해보자&lt;/p&gt;

&lt;h3 id=&quot;update&quot;&gt;UPDATE&lt;/h3&gt;

&lt;p&gt;예시는 아래 코드로 시작한다.&lt;/p&gt;
&lt;div class=&quot;language-javascript highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kd&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;oneDiv&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;document&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;createElement&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;div&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h4 id=&quot;1-비어있는-엘리먼트에-문자열-추가하기&quot;&gt;1. 비어있는 엘리먼트에 문자열 추가하기&lt;/h4&gt;
&lt;p&gt;&lt;strong&gt;&lt;span style=&quot;color: tomato; font-size: 1.2rem&quot;&gt;textContent&lt;/span&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;div class=&quot;language-javascript highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nx&quot;&gt;oneDiv&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;textContent&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;dev&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;nx&quot;&gt;console&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;oneDiv&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;//&amp;lt;div&amp;gt;dev&amp;lt;/div&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h4 id=&quot;2-엘리먼트에-class-추가하기&quot;&gt;2. 엘리먼트에 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;class&lt;/code&gt; 추가하기&lt;/h4&gt;
&lt;p&gt;CSS스타일링 적용 등 클래스가 필요할 때 사용한다.&lt;br /&gt;
&lt;strong&gt;&lt;span style=&quot;color: tomato; font-size: 1.2rem&quot;&gt;classList.add&lt;/span&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;div class=&quot;language-javascript highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nx&quot;&gt;oneDiv&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;classList&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;add&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;tweet&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;nx&quot;&gt;console&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;oneDiv&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;// &amp;lt;div class=&quot;tweet&quot;&amp;gt;dev&amp;lt;/div&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;텍스트를 넣고, 클래스를 추가해 CSS까지 적용되게 한 후 다시 append한다.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/img/2023-01-18/update.png&quot; alt=&quot;update&quot; /&gt;&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;class, id 말고 다른 속성(attribute)추가하려면 -&amp;gt; &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;setAttribute&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;delete&quot;&gt;DELETE&lt;/h3&gt;
&lt;p&gt;삭제하는 방법에도 여러 가지가 있다.&lt;/p&gt;

&lt;h4 id=&quot;1-삭제하려는-요소의-위치를-알고-있는-경우&quot;&gt;1. 삭제하려는 요소의 위치를 알고 있는 경우&lt;/h4&gt;
&lt;p&gt;앞서 생성하고 추가한 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;tweetDiv&lt;/code&gt;를 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;remove&lt;/code&gt; 메서드를 이용해 삭제해보자&lt;/p&gt;

&lt;div class=&quot;language-javascript highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kd&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;container&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;document&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;querySelector&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;#container&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;kd&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;tweetDiv&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;document&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;createElement&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;div&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;nx&quot;&gt;container&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;append&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;tweetDiv&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;nx&quot;&gt;tweetDiv&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;remove&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;// 이렇게 append 했던 요소를 삭제할 수 있다.&lt;/span&gt;

&lt;span class=&quot;c1&quot;&gt;//id가 container인 요소 아래에 TweetDiv를 추가하고, remove로 삭제한다.&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;2-여러-개의-자식-요소를-지우고-싶다면&quot;&gt;2. 여러 개의 자식 요소를 지우고 싶다면&lt;/h3&gt;
&lt;p&gt;&lt;span style=&quot;color: tomato; font-size: 1.2rem&quot;&gt;innerHTML&lt;/span&gt;을 이용한다.&lt;/p&gt;

&lt;div class=&quot;language-javascript highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;c1&quot;&gt;// 컨테이너의 모든 자식 요소를 지우려면,&lt;/span&gt;
&lt;span class=&quot;nb&quot;&gt;document&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;querySelector&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;#container&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;).&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;innerHTML&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;''&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;innerHTML&lt;/code&gt;은 분명 편리하나 &lt;span style=&quot;color: royalblue&quot;&gt;보안에서 몇 가지 문제를 가지고 있기에&lt;/span&gt; 다른 메서드를 사용한다.&lt;/p&gt;

&lt;p&gt;&lt;span style=&quot;color: tomato; font-size: 1.2rem&quot;&gt;removeChild&lt;/span&gt;&lt;/p&gt;

&lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;removeChild&lt;/code&gt;는 자식 요소를 지정해서 삭제하는 메서드이다.&lt;br /&gt;
모든 자식 요소를 삭제하기 위해, 반복문(for, while, etc)을 활용할 수 있다.&lt;/p&gt;

&lt;div class=&quot;language-javascript highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;c1&quot;&gt;//자식 요소가 남아있지 않을 때까지 첫 번째 자식 요소를 삭제하는 코드&lt;/span&gt;

&lt;span class=&quot;kd&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;container&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;document&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;querySelector&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;#container&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;while&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;container&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;firstChild&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;){&lt;/span&gt;
  &lt;span class=&quot;nx&quot;&gt;container&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;removeChild&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;container&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;firstChild&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;c1&quot;&gt;//container의 첫 번째 자식 요소가 존재하면, 첫 번째 자식 요소를 제거한다&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p class=&quot;figcaption&quot;&gt;&lt;img src=&quot;/assets/img/2023-01-20/delete.gif&quot; alt=&quot;delete&quot; /&gt;
&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;removeChild&lt;/code&gt;와 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;while&lt;/code&gt;을 사용해 자식 요소를 삭제하면 제목인 H2 “Tweet List”까지 삭제된다.&lt;br /&gt;
이를 방지하는 많은 방법 중 세가지를 아래에 기술하자면&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;자식 요소가 담고 있는 문자열을 비교해 “Tweet List”만 남기거나,&lt;/li&gt;
  &lt;li&gt;새로운 변수를 생성하고 Tweet List를 할당해뒀다가 반복문이 끝난 뒤에 새롭게 추가하거나&lt;/li&gt;
  &lt;li&gt;혹은 자식 요소를 하나만 남기게 하거나&lt;/li&gt;
  &lt;li&gt;직접 클래스 이름이 ‘tweet’인 요소만 찾아 지우는 방법이 있다.&lt;/li&gt;
&lt;/ol&gt;

&lt;div class=&quot;language-javascript highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;c1&quot;&gt;//3. 자식 요소 하나만 남기기&lt;/span&gt;

&lt;span class=&quot;kd&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;container&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;document&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;querySelector&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;#container&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;while&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;container&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;children&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;length&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;){&lt;/span&gt;
  &lt;span class=&quot;nx&quot;&gt;container&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;removeChild&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;container&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;lastChild&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;


&lt;span class=&quot;c1&quot;&gt;//4. 클래스 이름이 tweet인 요소만 찾아 제거하기&lt;/span&gt;

&lt;span class=&quot;kd&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;tweets&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;document&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;querySelectorAll&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;.tweet&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;nx&quot;&gt;tweets&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;forEach&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kd&quot;&gt;function&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;tweet&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;){&lt;/span&gt;
  &lt;span class=&quot;nx&quot;&gt;tweet&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;remove&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;();&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;})&lt;/span&gt;

&lt;span class=&quot;c1&quot;&gt;//혹은&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;for&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kd&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;tweet&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;of&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;tweets&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;){&lt;/span&gt;
  &lt;span class=&quot;nx&quot;&gt;tweet&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;remove&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;();&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p class=&quot;figcaption&quot;&gt;&lt;img src=&quot;/assets/img/2023-01-20/delete2.gif&quot; alt=&quot;delete2&quot; /&gt;
클래스 이름이 ‘tweet’인 요소를 모두 삭제한다&lt;/p&gt;</content><author><name>Subin Cho</name><email>lunadein2022@gmail.com</email></author><category term="Study" /><category term="study" /><category term="javascript" /><summary type="html"></summary><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://lunadein2022.github.io/assets/img/thumbnail/js.png" /><media:content medium="image" url="https://lunadein2022.github.io/assets/img/thumbnail/js.png" xmlns:media="http://search.yahoo.com/mrss/" /></entry><entry><title type="html">[JS] 이벤트 객체</title><link href="https://lunadein2022.github.io/study/basic1-10-2.html" rel="alternate" type="text/html" title="[JS] 이벤트 객체" /><published>2023-01-18T00:00:00+09:00</published><updated>2023-01-18T00:00:00+09:00</updated><id>https://lunadein2022.github.io/study/basic1-10-2</id><content type="html" xml:base="https://lunadein2022.github.io/study/basic1-10-2.html">&lt;ul id=&quot;markdown-toc&quot;&gt;
  &lt;li&gt;&lt;a href=&quot;#이벤트&quot; id=&quot;markdown-toc-이벤트&quot;&gt;이벤트&lt;/a&gt;    &lt;ul&gt;
      &lt;li&gt;&lt;a href=&quot;#이벤트의-종류&quot; id=&quot;markdown-toc-이벤트의-종류&quot;&gt;이벤트의 종류&lt;/a&gt;        &lt;ul&gt;
          &lt;li&gt;&lt;a href=&quot;#기본&quot; id=&quot;markdown-toc-기본&quot;&gt;기본&lt;/a&gt;&lt;/li&gt;
          &lt;li&gt;&lt;a href=&quot;#마우스-이벤트&quot; id=&quot;markdown-toc-마우스-이벤트&quot;&gt;마우스 이벤트&lt;/a&gt;&lt;/li&gt;
          &lt;li&gt;&lt;a href=&quot;#키보드-이벤트&quot; id=&quot;markdown-toc-키보드-이벤트&quot;&gt;키보드 이벤트&lt;/a&gt;&lt;/li&gt;
          &lt;li&gt;&lt;a href=&quot;#폼-이벤트&quot; id=&quot;markdown-toc-폼-이벤트&quot;&gt;폼 이벤트&lt;/a&gt;&lt;/li&gt;
          &lt;li&gt;&lt;a href=&quot;#값-변경-이벤트&quot; id=&quot;markdown-toc-값-변경-이벤트&quot;&gt;값 변경 이벤트&lt;/a&gt;&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;#이벤트-객체&quot; id=&quot;markdown-toc-이벤트-객체&quot;&gt;이벤트 객체&lt;/a&gt;        &lt;ul&gt;
          &lt;li&gt;&lt;a href=&quot;#이벤트-객체의-주요-속성-property&quot; id=&quot;markdown-toc-이벤트-객체의-주요-속성-property&quot;&gt;이벤트 객체의 주요 속성 (property)&lt;/a&gt;&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;#이벤트-핸들러-이벤트-리스너&quot; id=&quot;markdown-toc-이벤트-핸들러-이벤트-리스너&quot;&gt;이벤트 핸들러 (이벤트 리스너)&lt;/a&gt;        &lt;ul&gt;
          &lt;li&gt;&lt;a href=&quot;#이벤트-핸들러-event-handler&quot; id=&quot;markdown-toc-이벤트-핸들러-event-handler&quot;&gt;이벤트 핸들러 (Event Handler)&lt;/a&gt;&lt;/li&gt;
          &lt;li&gt;&lt;a href=&quot;#이벤트-리스너-event-listener&quot; id=&quot;markdown-toc-이벤트-리스너-event-listener&quot;&gt;이벤트 리스너 (Event Listener)&lt;/a&gt;&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#실습&quot; id=&quot;markdown-toc-실습&quot;&gt;실습&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;!--more--&gt;

&lt;h2 id=&quot;이벤트&quot;&gt;이벤트&lt;/h2&gt;
&lt;p&gt;이벤트는 사용자의 어떤 행동에 의해 생기는 어떤 변화를 말한다.&lt;br /&gt;
이벤트가 발생하는 시점이나 순서는 ‘사용자’ 맘대로이므로 접근방식이 달라야 한다.&lt;/p&gt;

&lt;p&gt;이벤트 실행 방식은 다음과 같다.&lt;br /&gt;
이벤트 발생! =&amp;gt; 이벤트 감지! =&amp;gt; 이벤트 처리!&lt;/p&gt;

&lt;p&gt;이 때, 이벤트가 발생하면 실행하는 함수를 &lt;span style=&quot;color: tomato; font-size: 1.2rem&quot;&gt;이벤트 핸들러&lt;/span&gt;라고 한다.&lt;/p&gt;

&lt;h3 id=&quot;이벤트의-종류&quot;&gt;이벤트의 종류&lt;/h3&gt;

&lt;h4 id=&quot;기본&quot;&gt;기본&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;‘a’ 요소를 클릭 하면 해당 페이지로 이동&lt;/li&gt;
  &lt;li&gt;브라우저 화면에서 우측 마우스 클릭시 나오는 메뉴&lt;/li&gt;
  &lt;li&gt;‘form’요소 내 ‘submit’ 버튼 클릭하면 지정 경로로 내용 전송&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;마우스-이벤트&quot;&gt;마우스 이벤트&lt;/h4&gt;
&lt;p&gt;|이벤트명|설명|
|—-|—–|
|클릭| |
|click (onclick)|마우스 버튼 클릭후 손 떼기|
| | el.onclick : “이벤트 처리”;|
| | el.addEventListener(“click”,이벤트 처리 및 콜백함수)|
|dbclick (ondbclick)|마우스 버튼을 두 번 연속 더블 클릭|&lt;/p&gt;

&lt;h4 id=&quot;키보드-이벤트&quot;&gt;키보드 이벤트&lt;/h4&gt;
&lt;p&gt;|이벤트명|설명|
|—–|—-|
|keydown (onkeydown)|키를 누르는 순간|
|keyup (onkeyup)|키를 눌렀다 떼는 순간|
|keypress (onkeypress)|키를 눌러 문자가 연결되었을 때|
| |= 화면에 글자가 완성되는 경우|
| |= 그리고 키를 누르고 있는 동안 이벤트도 계속 발생됨|&lt;/p&gt;

&lt;h4 id=&quot;폼-이벤트&quot;&gt;폼 이벤트&lt;/h4&gt;
&lt;p&gt;|이벤트명|설명|
|—–|—-|
|submit (onsubmit)| 폼 제출 버튼 누르기|
| |버튼 누르거나 필드에서 엔터 누르기|
|reset (onreset)|폼을 초기화하기|
|change (onchange)|폼 필드에서 변경이 일어남 (input 요소의 텍스트 변동, radio 버튼의 클릭 등)|
|focus (onfocus)|웹브라우저가 특정요소에 포커싱함|
| |예를 들어 해당 요소를클릭하거나 마우스 커서를 놓을 때 등|
|select (onselect)|텍스트 필드 등의 텍스트 선택했을 때|&lt;/p&gt;

&lt;h4 id=&quot;값-변경-이벤트&quot;&gt;값 변경 이벤트&lt;/h4&gt;
&lt;p&gt;|이벤트명|설명|
|——|—|
|input (oninput)|값이 입력될 때|
| |input (text, checkbox, radio), select, textarea 요소 내 값이 입력될 때|
|change (onchange)|폼 필드에서 변경이 일어남|
| |input요소의 텍스트 변동, radio 버튼의 클릭 등|
| |input(text, checkbox, radio), select, textarea 요소 내 값이 변경될 때|&lt;/p&gt;

&lt;h3 id=&quot;이벤트-객체&quot;&gt;이벤트 객체&lt;/h3&gt;
&lt;p&gt;이벤트 객체는 이벤트 발생시 전달되는 정보.&lt;br /&gt;
특정 이벤트와 연관된 객체로, 해당 이벤트에 대한 정보를 담고 있다.&lt;br /&gt;
이는 이벤트 핸들러에 전달되는 인수(매개변수)이다.&lt;br /&gt;
보통 ==event, e, ev== 등으로 표시한다.&lt;/p&gt;

&lt;h4 id=&quot;이벤트-객체의-주요-속성-property&quot;&gt;이벤트 객체의 주요 속성 (property)&lt;/h4&gt;
&lt;p&gt;|속성명|설명|
|—-|—|
|type|이벤트 종류|
|target|이벤트를 발생시킨 요소 타겟팅  (ex. event.target.id)|
|currentTarget|&lt;span style=&quot;color: tomato:&quot;&gt;이벤트 버블링&lt;/span&gt;단계에서의 현재 요소를 가리킴|
|key|눌린 키의 값|
|keyCode|눌린 키의 코드|
|altKey|Alt키 눌린 여부 (true, false)|
|ctrlKey|Ctrl키 눌린 여부|
|shiftKey|시프트 키 눌린 여부|
|which|keypress 이벤트에서 눌린 키 코드의 값|&lt;/p&gt;

&lt;h3 id=&quot;이벤트-핸들러-이벤트-리스너&quot;&gt;이벤트 핸들러 (이벤트 리스너)&lt;/h3&gt;
&lt;p&gt;이벤트가 발생했을 때, 이에 반응하도록 ==실행 코드에 연결== 하는 처리기 혹은 실행을 담당하는 코드.&lt;/p&gt;

&lt;h4 id=&quot;이벤트-핸들러-event-handler&quot;&gt;이벤트 핸들러 (Event Handler)&lt;/h4&gt;
&lt;p&gt;==하나의 요소==에 ==하나의 이벤트=만 처리 가능&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;HTML요소의 ==on—-==속성에 등록하기 (태그에 직접 지정 -&amp;gt; 인라인 이벤트 핸들러)&lt;br /&gt;
그러나 ==관심사 분리==를 위해 리액트 등의 프레임워크/라이브러리에서 작성하는게 아닌 이상 인라인 이벤트 핸들러 방식으로 이벤트를 처리하지 않는게 좋다.&lt;/li&gt;
&lt;/ol&gt;

&lt;div class=&quot;language-javascript highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;button&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;onclick&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;func()&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;클릭하라&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;sr&quot;&gt;/button&lt;/span&gt;&lt;span class=&quot;err&quot;&gt;&amp;gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;ol&gt;
  &lt;li&gt;JS에서 DOM요소의 프로퍼티에 등록하기&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;case1.&lt;/p&gt;
&lt;div class=&quot;language-javascript highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nx&quot;&gt;el&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;onclick&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;Function&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;

&lt;span class=&quot;c1&quot;&gt;//객체명.on이벤트명 = 호출할 함수명;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;case2.&lt;/p&gt;
&lt;div class=&quot;language-javascript highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nx&quot;&gt;el&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;onclick&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;function&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(){&lt;/span&gt;
  &lt;span class=&quot;nx&quot;&gt;console&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;클릭했나&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h4 id=&quot;이벤트-리스너-event-listener&quot;&gt;이벤트 리스너 (Event Listener)&lt;/h4&gt;
&lt;p&gt;==하나의 요소==에 ==여러 이벤트== 처리 가능&lt;br /&gt;
&lt;span style=&quot;color: tomato; font-size: 1.2rem&quot;&gt;이벤트 핸들러보다 요걸 자주 쓰자.&lt;/span&gt;&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;addEventListener 메소드 등록하기
    &lt;ol&gt;
      &lt;li&gt;HTML태그요소에 해당 이벤트 리스너를 요소 객체의 메소드와 연결시켜 이벤트가 발생했을 때, 원하는 처리 실행하기.&lt;/li&gt;
    &lt;/ol&gt;

    &lt;p&gt;&lt;span style=&quot;color: tomato; font-size: 1.2rem&quot;&gt;target.addEventListener(type, 콜백함수[,타겟팅종류])&lt;/span&gt;&lt;/p&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;type: 이벤트 유형(‘click’, ‘dbclick’등)&lt;br /&gt;
  콜백함수: 이벤트 처리 내역&lt;br /&gt;
  타겟팅 종류: true/false(true: 캡처링, flase: 버블링 단계/기본값)&lt;/p&gt;

&lt;h2 id=&quot;실습&quot;&gt;실습&lt;/h2&gt;
&lt;p&gt;커피, 주스라는 버튼을 만들어,&lt;br /&gt;
각 버튼을 누를 때마다 콘솔에 출력시키기.&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;html 만들기&lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;language-javascript highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;body&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;button&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;커피&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;sr&quot;&gt;/button&lt;/span&gt;&lt;span class=&quot;err&quot;&gt;&amp;gt;
&lt;/span&gt;    &lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;button&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;주스&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;sr&quot;&gt;/button&lt;/span&gt;&lt;span class=&quot;err&quot;&gt;&amp;gt;
&lt;/span&gt;    &lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;script&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;src&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;script.js&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;sr&quot;&gt;/script&lt;/span&gt;&lt;span class=&quot;err&quot;&gt;&amp;gt;
&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;sr&quot;&gt;/body&lt;/span&gt;&lt;span class=&quot;err&quot;&gt;&amp;gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;ul&gt;
  &lt;li&gt;script 작성&lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;language-javascript highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kd&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;menus&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;document&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;querySelectorAll&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;button&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;

&lt;span class=&quot;kd&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;btnCoffie&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;menus&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;];&lt;/span&gt;
&lt;span class=&quot;kd&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;btnJuice&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;menus&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;];&lt;/span&gt;
  
&lt;span class=&quot;nx&quot;&gt;btnCoffie&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;onclick&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;handleClick&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;nx&quot;&gt;btnJuice&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;onclick&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;handleClick&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;


&lt;span class=&quot;kd&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;handleClick&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;event&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;kd&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;currentMenu&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;event&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;target&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;textContent&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;c1&quot;&gt;//btnCoffie 혹은 btnJuice 요소의 '텍스트' = currentMenu&lt;/span&gt;
    &lt;span class=&quot;nx&quot;&gt;console&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;currentMenu&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;를 주문하셨습니다만 문제라도?&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;</content><author><name>Subin Cho</name><email>lunadein2022@gmail.com</email></author><category term="Study" /><category term="study" /><category term="javascript" /><summary type="html"></summary><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://lunadein2022.github.io/assets/img/thumbnail/js.png" /><media:content medium="image" url="https://lunadein2022.github.io/assets/img/thumbnail/js.png" xmlns:media="http://search.yahoo.com/mrss/" /></entry><entry><title type="html">[JS] 배열과 객체</title><link href="https://lunadein2022.github.io/study/basic1-8-1.html" rel="alternate" type="text/html" title="[JS] 배열과 객체" /><published>2023-01-14T00:00:00+09:00</published><updated>2023-01-14T00:00:00+09:00</updated><id>https://lunadein2022.github.io/study/basic1-8-1</id><content type="html" xml:base="https://lunadein2022.github.io/study/basic1-8-1.html">&lt;ul id=&quot;markdown-toc&quot;&gt;
  &lt;li&gt;&lt;a href=&quot;#배열&quot; id=&quot;markdown-toc-배열&quot;&gt;배열&lt;/a&gt;    &lt;ul&gt;
      &lt;li&gt;&lt;a href=&quot;#배열만들기&quot; id=&quot;markdown-toc-배열만들기&quot;&gt;배열만들기&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;#배열의-값에-접근하기&quot; id=&quot;markdown-toc-배열의-값에-접근하기&quot;&gt;배열의 값에 접근하기&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;#배열의-값을-변경하려면&quot; id=&quot;markdown-toc-배열의-값을-변경하려면&quot;&gt;배열의 값을 변경하려면&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;#배열-활용하기&quot; id=&quot;markdown-toc-배열-활용하기&quot;&gt;배열 활용하기&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;#배열--반복문--배열-반복하기&quot; id=&quot;markdown-toc-배열--반복문--배열-반복하기&quot;&gt;배열 + 반복문 = 배열 반복하기&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;#그-외-배열-메서드들&quot; id=&quot;markdown-toc-그-외-배열-메서드들&quot;&gt;그 외 배열 메서드들&lt;/a&gt;&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#객체&quot; id=&quot;markdown-toc-객체&quot;&gt;객체&lt;/a&gt;    &lt;ul&gt;
      &lt;li&gt;&lt;a href=&quot;#객체만들기&quot; id=&quot;markdown-toc-객체만들기&quot;&gt;객체만들기&lt;/a&gt;        &lt;ul&gt;
          &lt;li&gt;&lt;a href=&quot;#객체-리터럴&quot; id=&quot;markdown-toc-객체-리터럴&quot;&gt;객체 리터럴&lt;/a&gt;&lt;/li&gt;
          &lt;li&gt;&lt;a href=&quot;#object-생성자-함수&quot; id=&quot;markdown-toc-object-생성자-함수&quot;&gt;Object 생성자 함수&lt;/a&gt;&lt;/li&gt;
          &lt;li&gt;&lt;a href=&quot;#생성자-함수&quot; id=&quot;markdown-toc-생성자-함수&quot;&gt;생성자 함수&lt;/a&gt;&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;#객체의-키와-값에-접근하기&quot; id=&quot;markdown-toc-객체의-키와-값에-접근하기&quot;&gt;객체의 키와 값에 접근하기&lt;/a&gt;        &lt;ul&gt;
          &lt;li&gt;&lt;a href=&quot;#키-in-연산자-사용해-확인하기-keys-사용해-접근하기&quot; id=&quot;markdown-toc-키-in-연산자-사용해-확인하기-keys-사용해-접근하기&quot;&gt;키 (in 연산자 사용해 확인하기, keys 사용해 접근하기)&lt;/a&gt;&lt;/li&gt;
          &lt;li&gt;&lt;a href=&quot;#값-마침표-대괄호표기법-values&quot; id=&quot;markdown-toc-값-마침표-대괄호표기법-values&quot;&gt;값 (마침표(.), 대괄호([])표기법, .values())&lt;/a&gt;&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;#객체의-키와-값을-변경하려면&quot; id=&quot;markdown-toc-객체의-키와-값을-변경하려면&quot;&gt;객체의 키와 값을 변경하려면&lt;/a&gt;&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;!--more--&gt;

&lt;h1 id=&quot;배열&quot;&gt;배열&lt;/h1&gt;

&lt;h2 id=&quot;배열만들기&quot;&gt;배열만들기&lt;/h2&gt;
&lt;p&gt;배열은 순서가 있는 값이다.&lt;br /&gt;
순서는 ==인덱스==라고 부르며 ==1이 아닌 0부터== 번호를 매긴다.&lt;/p&gt;

&lt;p&gt;각각의 엘리먼트는 쉼포로 구분하고, 대괄호를 이용해 배열을 만든다.&lt;br /&gt;
&lt;span style=&quot;color: tomato; font-size: 1.2rem&quot;&gt;let order = [a, b, c, d, e]&lt;/span&gt;&lt;br /&gt;
order라는 배열의 0번째 인덱스 값은 a이다.&lt;/p&gt;

&lt;h2 id=&quot;배열의-값에-접근하기&quot;&gt;배열의 값에 접근하기&lt;/h2&gt;
&lt;p&gt;값은 인덱스를 이용해 접근한다.&lt;/p&gt;

&lt;p&gt;위의 예시를 참고하여 order라는 배열의 0번째 인덱스를 ==조회==하려면&lt;br /&gt;
&lt;span style=&quot;color: tomato; font-size: 1.2rem&quot;&gt;order[0] //a&lt;/span&gt;&lt;/p&gt;

&lt;h2 id=&quot;배열의-값을-변경하려면&quot;&gt;배열의 값을 변경하려면&lt;/h2&gt;

&lt;p&gt;&lt;span style=&quot;color: tomato; font-size: 1.2rem&quot;&gt;order[3] = 321;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: tomato; font-size: 1.2rem&quot;&gt;console.log(order) // [a, b, c, 321, e]&lt;/span&gt;&lt;/p&gt;

&lt;h2 id=&quot;배열-활용하기&quot;&gt;배열 활용하기&lt;/h2&gt;
&lt;ol&gt;
  &lt;li&gt;길이 알아내기 (.length)&lt;br /&gt;
order길이 알아내려면 =&amp;gt; ==order.length== //5&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;(.(dot)을 이용해 변수가 갖고 있는 속성(property)에 접근할 수 있다.)&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;요소 추가하고 삭제하기 (.push, .pop, .unshift, .shift)
    &lt;ol&gt;
      &lt;li&gt;order 맨 뒤에 요소 추가하기(.push)
        &lt;div class=&quot;language-javascript highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt; &lt;span class=&quot;nx&quot;&gt;order&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;push&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;// [a, b, c, 321, e, 3]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;        &lt;/div&gt;
      &lt;/li&gt;
      &lt;li&gt;order 맨 뒤에 요소 삭제하기(.pop)
        &lt;div class=&quot;language-javascript highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt; &lt;span class=&quot;nx&quot;&gt;order&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;pop&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;// [a, b, c, 321, e]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;        &lt;/div&gt;
      &lt;/li&gt;
      &lt;li&gt;order 맨 앞에 요소 추가하기(.unshift)
        &lt;div class=&quot;language-javascript highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt; &lt;span class=&quot;nx&quot;&gt;order&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;unshift&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;// [1, a, b, c, 321, e]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;        &lt;/div&gt;
      &lt;/li&gt;
      &lt;li&gt;order 맨 앞에 요소 삭제하기(.shift)
        &lt;div class=&quot;language-javascript highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt; &lt;span class=&quot;nx&quot;&gt;order&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;shift&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;// [a, b, c, 321, e]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;        &lt;/div&gt;
      &lt;/li&gt;
    &lt;/ol&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;배열--반복문--배열-반복하기&quot;&gt;배열 + 반복문 = 배열 반복하기&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;배열의 요소를 한 번씩 출력하자&lt;/li&gt;
&lt;/ol&gt;

&lt;div class=&quot;language-javascript highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kd&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;myNum&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;5&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;4&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;

&lt;span class=&quot;c1&quot;&gt;//배열 myNum의 n번째 인덱스를 출력하자 === 배열의 요소를 한번씩 모두 출력하자.&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;//1. n은 0부터 시작한다&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;//2. n을 배열의 길이보다 작을 때까지 반복한다 (index가 0부터이므로)&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;//3. n은 반복문이 실행될 때마다 1씩 증가한다.&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;for&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kd&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;n&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;n&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;myNum&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;length&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;n&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;++&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;){&lt;/span&gt;
  &lt;span class=&quot;nx&quot;&gt;console&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;myNum&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;n&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;])&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h2 id=&quot;그-외-배열-메서드들&quot;&gt;그 외 배열 메서드들&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;Array.isArray()
이 값이 배열인지 아닌지 판별할 수 있다.
    &lt;div class=&quot;language-javascript highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nb&quot;&gt;Array&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;isArray&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;([&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]);&lt;/span&gt;  &lt;span class=&quot;c1&quot;&gt;// true&lt;/span&gt;
&lt;span class=&quot;nb&quot;&gt;Array&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;isArray&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;({&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;foo&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;123&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;});&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;// false&lt;/span&gt;
&lt;span class=&quot;nb&quot;&gt;Array&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;isArray&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;foobar&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;   &lt;span class=&quot;c1&quot;&gt;// false&lt;/span&gt;
&lt;span class=&quot;nb&quot;&gt;Array&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;isArray&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kc&quot;&gt;undefined&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;  &lt;span class=&quot;c1&quot;&gt;// false&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;    &lt;/div&gt;
  &lt;/li&gt;
  &lt;li&gt;indexOf()
배열에서 지정된 요소를 찾을 수 있는 첫 번째 인덱스를 리턴한다.&lt;br /&gt;
존재하지 않으면 -1을 리턴한다.&lt;/li&gt;
&lt;/ol&gt;

&lt;div class=&quot;language-javascript highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kd&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;beasts&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;ant&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;bison&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;camel&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;duck&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;bison&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;];&lt;/span&gt;

&lt;span class=&quot;nx&quot;&gt;console&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;beasts&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;indexOf&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;bison&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;));&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;// Expected output: 1&lt;/span&gt;

&lt;span class=&quot;c1&quot;&gt;// Start from index 2&lt;/span&gt;
&lt;span class=&quot;nx&quot;&gt;console&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;beasts&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;indexOf&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;bison&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;));&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;// Expected output: 4&lt;/span&gt;

&lt;span class=&quot;nx&quot;&gt;console&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;beasts&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;indexOf&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;giraffe&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;));&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;// Expected output: -1&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;ol&gt;
  &lt;li&gt;includes()
배열이 특정 요소를 포함하고 있는지 판별한다.&lt;/li&gt;
&lt;/ol&gt;

&lt;div class=&quot;language-javascript highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;  &lt;span class=&quot;kd&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;array1&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;];&lt;/span&gt;

  &lt;span class=&quot;nx&quot;&gt;console&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;array1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;includes&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;));&lt;/span&gt;
  &lt;span class=&quot;c1&quot;&gt;// Expected output: true&lt;/span&gt;

  &lt;span class=&quot;kd&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;pets&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;cat&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;dog&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;bat&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;];&lt;/span&gt;

  &lt;span class=&quot;nx&quot;&gt;console&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;pets&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;includes&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;cat&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;));&lt;/span&gt;
  &lt;span class=&quot;c1&quot;&gt;// Expected output: true&lt;/span&gt;

  &lt;span class=&quot;nx&quot;&gt;console&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;pets&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;includes&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;at&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;));&lt;/span&gt;
  &lt;span class=&quot;c1&quot;&gt;// Expected output: false&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h1 id=&quot;객체&quot;&gt;객체&lt;/h1&gt;
&lt;p&gt;키와 값으로 구성된 프로퍼티들의 집합.&lt;br /&gt;
원시타입을 제외한 나머지 값(함수, 배열, 정규표현식 등)은 모두 객체.&lt;/p&gt;

&lt;h2 id=&quot;객체만들기&quot;&gt;객체만들기&lt;/h2&gt;
&lt;h3 id=&quot;객체-리터럴&quot;&gt;객체 리터럴&lt;/h3&gt;
&lt;p&gt;가장 일반적인 객체 생성 방식.&lt;br /&gt;
중괄호를 사용하여 객체를 생성하는데 {}내에 1개 이상의 프로퍼티를 작성하면 해당 프로퍼티가 추기된 객체를 생성할 수 있다.&lt;br /&gt;
{}내에 아무 것도 작성하지 않으면 빈 객체가 생성된다.&lt;/p&gt;

&lt;div class=&quot;language-javascript highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;  &lt;span class=&quot;kd&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;me&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{};&lt;/span&gt;

  &lt;span class=&quot;kd&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;you&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;na&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;Lee&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;na&quot;&gt;gender&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;male&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;na&quot;&gt;hi&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;function&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(){&lt;/span&gt;
      &lt;span class=&quot;nx&quot;&gt;console&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;Hi!, How are you &lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
  &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;object-생성자-함수&quot;&gt;Object 생성자 함수&lt;/h3&gt;
&lt;p&gt;new연산자와 Object 생성자 함수를 호출하여 빈 객체를 생성할 수 있다.&lt;br /&gt;
빈 객체 생성 이후 프로퍼티 또는 메소드를 추가해 객체를 완성하는 방법. (사용빈도수는 낮다.)&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;빈 객체를 만든다&lt;/li&gt;
  &lt;li&gt;객체가 소유하고 있지 않은 프로퍼티 키에 값을 할당한다&lt;/li&gt;
  &lt;li&gt;이미 존재하는 프로퍼티 키에 새로운 값을 할당하면 프로퍼티 값은 할당한 값으로 변경된다. (덮어쓰기)&lt;/li&gt;
&lt;/ol&gt;

&lt;ul&gt;
  &lt;li&gt;생성자 함수란 new키워드와 함께 객체를 생성하고 초기화하는 함수.&lt;/li&gt;
  &lt;li&gt;생성자 함수를 통해 생성된 객체를 인스턴스라고 함.&lt;/li&gt;
  &lt;li&gt;생성자 함수의 이름은 파스칼 케이스를 사용하는 것이 일반적이다 (구분하기 위해서)&lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;language-javascript highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;  &lt;span class=&quot;kd&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;person&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;Object&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;();&lt;/span&gt;

  &lt;span class=&quot;nx&quot;&gt;person&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;name&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;Jaw&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;nx&quot;&gt;person&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;gender&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;female&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;nx&quot;&gt;person&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;hi&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;function&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(){&lt;/span&gt;
    &lt;span class=&quot;nx&quot;&gt;console&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;say it &lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
  &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;

  &lt;span class=&quot;nx&quot;&gt;console&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;person&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
  &lt;span class=&quot;c1&quot;&gt;//{name: 'Jaw', gender: 'female', hi: f} &lt;/span&gt;
  &lt;span class=&quot;c1&quot;&gt;//f -&amp;gt; function&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;생성자-함수&quot;&gt;생성자 함수&lt;/h3&gt;
&lt;p&gt;위의 방식들은 프로퍼티 값만 다른 여러 개의객체를 생성할 때 불편하다.&lt;br /&gt;
동일한 프로퍼티를 갖는 객체임에도 매번 같은 프로퍼티를 작성해야하기 때문이다. (노가다)&lt;br /&gt;
생성자 함수를 사용하면 객체 생성 템플릿마냥 뚝딱 찍어낼 수 있다.&lt;/p&gt;

&lt;div class=&quot;language-javascript highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;  &lt;span class=&quot;kd&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;Person&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;gender&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;){&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;name&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;gender&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;gender&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;hi&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;function&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(){&lt;/span&gt;
      &lt;span class=&quot;nx&quot;&gt;console&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;say it &lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;};&lt;/span&gt;
  &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;

  &lt;span class=&quot;kd&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;person1&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;Jaw&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;female&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
  &lt;span class=&quot;kd&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;person2&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;Yang&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;male&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;ul&gt;
  &lt;li&gt;생성자 함수 이름은 일반적으로 대문자로 시작한다.&lt;/li&gt;
  &lt;li&gt;프로퍼티 또는 메소드명 앞에 작성한 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;this&lt;/code&gt;는 생성자 함수가 생성할 인스턴스를 가리킨다.&lt;/li&gt;
  &lt;li&gt;this에 연결(바인딩)되어 있는 프로퍼티와 메소드는 외부에서 참조 가능하다. (public)&lt;/li&gt;
  &lt;li&gt;생성자 함수 내에서 선언된 일반 변수는 외부에서 참조 불가하다. (private)&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;객체의-키와-값에-접근하기&quot;&gt;객체의 키와 값에 접근하기&lt;/h2&gt;
&lt;p&gt;프로퍼티 키는 일반적으로 문자열(빈 문자열 포함)을 지정함. (따옴표 사용함)&lt;br /&gt;
(그 외 값을 지정하면 암묵적으로 타입변환되어 문자열이 된다.)&lt;br /&gt;
(자바스크립트에 사용 가능한 이름인 경우 따옴표 생략 가능 그 외에는 따옴표 붙이기)&lt;br /&gt;
(표현식을 키로 사용하려면 대괄호로 묶어야 함.)&lt;br /&gt;
(예약어는 쓰지 프로퍼티 키로 쓰지 말자.)&lt;br /&gt;
프로퍼티 값은 모든 값과 표현식이 올 수 있으며 함수인 경우 메소드라 한다.&lt;/p&gt;

&lt;h3 id=&quot;키-in-연산자-사용해-확인하기-keys-사용해-접근하기&quot;&gt;키 (in 연산자 사용해 확인하기, keys 사용해 접근하기)&lt;/h3&gt;
&lt;p&gt;in연산자를 사용해 해당 키가 존재하는지 확인할 수 있다.&lt;/p&gt;

&lt;div class=&quot;language-javascript highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;  &lt;span class=&quot;c1&quot;&gt;//person이라는 객체가 있다고 치고&lt;/span&gt;

  &lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;content&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;person&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;//트루나 폴스 하나 중에 나올 것임&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;.keys()&lt;/p&gt;

&lt;div class=&quot;language-javascript highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;  &lt;span class=&quot;c1&quot;&gt;//person이라는 객체가 있다고 치고&lt;/span&gt;

  &lt;span class=&quot;nb&quot;&gt;Object&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;keys&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;person&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
  &lt;span class=&quot;c1&quot;&gt;// (4) ['1', 'first-name', 'last-name', 'gender']&lt;/span&gt;

  &lt;span class=&quot;kd&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;name&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;Object&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;keys&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;person&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;// first-name&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;값-마침표-대괄호표기법-values&quot;&gt;값 (마침표(.), 대괄호([])표기법, .values())&lt;/h3&gt;

&lt;div class=&quot;language-javascript highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;  &lt;span class=&quot;kd&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;person&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;first-name&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;bean&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;last-name&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;Jaws&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;na&quot;&gt;gender&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;female&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;10&lt;/span&gt;
  &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;

  &lt;span class=&quot;nx&quot;&gt;console&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;person&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;first&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;//NaN: undefined-undefined&lt;/span&gt;
  &lt;span class=&quot;nx&quot;&gt;console&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;person&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;first&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]);&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;//ReferenceError: first is not defined&lt;/span&gt;
  &lt;span class=&quot;nx&quot;&gt;console&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;person&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;first-name&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]);&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;//'bean'&lt;/span&gt;

  &lt;span class=&quot;nx&quot;&gt;console&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;person&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;gender&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;//'female'&lt;/span&gt;
  &lt;span class=&quot;nx&quot;&gt;console&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;person&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;gender&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]);&lt;/span&gt;   &lt;span class=&quot;c1&quot;&gt;// ReferenceError: gender is not defined&lt;/span&gt;
  &lt;span class=&quot;nx&quot;&gt;console&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;person&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;gender&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]);&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;// 'female'&lt;/span&gt;

  &lt;span class=&quot;nx&quot;&gt;console&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;person&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]);&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;// 10&lt;/span&gt;
  &lt;span class=&quot;nx&quot;&gt;console&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;person&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]);&lt;/span&gt;   &lt;span class=&quot;c1&quot;&gt;// 10 : person[1] -&amp;gt; person['1']&lt;/span&gt;
  &lt;span class=&quot;nx&quot;&gt;console&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;person&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;  &lt;span class=&quot;c1&quot;&gt;//SyntaxError&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;ol&gt;
  &lt;li&gt;프로퍼티키 : 유효한 자바스크립트 이름 &amp;amp;&amp;amp; 예약어가 아닌 경우 =&amp;gt; 마침표, 대괄호 표기법 모두 이용 가능&lt;/li&gt;
  &lt;li&gt;프로퍼티키 : 유효한 자바스크립트 이름이 아니거나 예약어라면 =&amp;gt; 대괄호 표기법 이용 (프로퍼티 키는 반드시 문자열이어야 함)&lt;/li&gt;
  &lt;li&gt;객체에 존재하지 않는 프로퍼티를 참조하면 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;undefined&lt;/code&gt;&lt;/li&gt;
  &lt;li&gt;.values()&lt;/li&gt;
&lt;/ol&gt;

&lt;div class=&quot;language-javascript highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;
  &lt;span class=&quot;nb&quot;&gt;Object&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;values&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;person&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
  &lt;span class=&quot;c1&quot;&gt;// (4) ['1', 'first-name', 'last-name', 'gender']&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h2 id=&quot;객체의-키와-값을-변경하려면&quot;&gt;객체의 키와 값을 변경하려면&lt;/h2&gt;

&lt;div class=&quot;language-javascript highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;  &lt;span class=&quot;kd&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;person&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;na&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;lee&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;na&quot;&gt;gender&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;male&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;na&quot;&gt;age&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;49&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
  &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;ol&gt;
  &lt;li&gt;객체가 소유하고 있는 프로퍼티에 새로운 값 할당하기
    &lt;div class=&quot;language-javascript highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;  &lt;span class=&quot;nx&quot;&gt;person&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;name&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;Jaws&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;    &lt;/div&gt;
  &lt;/li&gt;
  &lt;li&gt;객체가 소유하고 있지 않은 프로퍼티 키에 값 할당하기 (객체에 추가하기)
    &lt;div class=&quot;language-javascript highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;  &lt;span class=&quot;nx&quot;&gt;person&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;hobby&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;sleep&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;  
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;    &lt;/div&gt;
  &lt;/li&gt;
  &lt;li&gt;프로퍼티를 삭제하려면 - &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;delete&lt;/code&gt;연산자 사용
    &lt;div class=&quot;language-javascript highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;  &lt;span class=&quot;k&quot;&gt;delete&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;person&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;hobby&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;    &lt;/div&gt;
  &lt;/li&gt;
&lt;/ol&gt;</content><author><name>Subin Cho</name><email>lunadein2022@gmail.com</email></author><category term="Study" /><category term="study" /><category term="javascript" /><summary type="html"></summary><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://lunadein2022.github.io/assets/img/thumbnail/js.png" /><media:content medium="image" url="https://lunadein2022.github.io/assets/img/thumbnail/js.png" xmlns:media="http://search.yahoo.com/mrss/" /></entry><entry><title type="html">[JS] 핵심 개념과 주요 문법은?</title><link href="https://lunadein2022.github.io/study/basic1-9-1.html" rel="alternate" type="text/html" title="[JS] 핵심 개념과 주요 문법은?" /><published>2023-01-13T00:00:00+09:00</published><updated>2023-01-13T00:00:00+09:00</updated><id>https://lunadein2022.github.io/study/basic1-9-1</id><content type="html" xml:base="https://lunadein2022.github.io/study/basic1-9-1.html">&lt;ul id=&quot;markdown-toc&quot;&gt;
  &lt;li&gt;&lt;a href=&quot;#원시-자료형--참조-자료형&quot; id=&quot;markdown-toc-원시-자료형--참조-자료형&quot;&gt;원시 자료형 &amp;amp; 참조 자료형&lt;/a&gt;    &lt;ul&gt;
      &lt;li&gt;&lt;a href=&quot;#원시자료형&quot; id=&quot;markdown-toc-원시자료형&quot;&gt;원시자료형&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;#참조자료형&quot; id=&quot;markdown-toc-참조자료형&quot;&gt;참조자료형&lt;/a&gt;&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#스코프&quot; id=&quot;markdown-toc-스코프&quot;&gt;스코프&lt;/a&gt;    &lt;ul&gt;
      &lt;li&gt;&lt;a href=&quot;#스코프의-주요-규칙&quot; id=&quot;markdown-toc-스코프의-주요-규칙&quot;&gt;스코프의 주요 규칙&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;#스코프와-변수-선언&quot; id=&quot;markdown-toc-스코프와-변수-선언&quot;&gt;스코프와 변수 선언&lt;/a&gt;        &lt;ul&gt;
          &lt;li&gt;&lt;a href=&quot;#var로-변수를-선언하면&quot; id=&quot;markdown-toc-var로-변수를-선언하면&quot;&gt;var로 변수를 선언하면?&lt;/a&gt;&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;#변수-선언에서-주의할-점&quot; id=&quot;markdown-toc-변수-선언에서-주의할-점&quot;&gt;변수 선언에서 주의할 점.&lt;/a&gt;&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#클로저&quot; id=&quot;markdown-toc-클로저&quot;&gt;클로저&lt;/a&gt;    &lt;ul&gt;
      &lt;li&gt;&lt;a href=&quot;#클로저의-특징&quot; id=&quot;markdown-toc-클로저의-특징&quot;&gt;클로저의 특징&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;#클로저의-활용&quot; id=&quot;markdown-toc-클로저의-활용&quot;&gt;클로저의 활용&lt;/a&gt;        &lt;ul&gt;
          &lt;li&gt;&lt;a href=&quot;#1-데이터를-보존하는-클로저-함수&quot; id=&quot;markdown-toc-1-데이터를-보존하는-클로저-함수&quot;&gt;1. 데이터를 보존하는 클로저 함수&lt;/a&gt;&lt;/li&gt;
          &lt;li&gt;&lt;a href=&quot;#2-클로저-모듈-패턴&quot; id=&quot;markdown-toc-2-클로저-모듈-패턴&quot;&gt;2. 클로저 모듈 패턴&lt;/a&gt;&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#es6-주요문법&quot; id=&quot;markdown-toc-es6-주요문법&quot;&gt;ES6 주요문법&lt;/a&gt;    &lt;ul&gt;
      &lt;li&gt;&lt;a href=&quot;#spread--rest&quot; id=&quot;markdown-toc-spread--rest&quot;&gt;spread / rest&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;#구조분해할당&quot; id=&quot;markdown-toc-구조분해할당&quot;&gt;구조분해할당&lt;/a&gt;&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;!--more--&gt;

&lt;h2 id=&quot;원시-자료형--참조-자료형&quot;&gt;원시 자료형 &amp;amp; 참조 자료형&lt;/h2&gt;

&lt;h3 id=&quot;원시자료형&quot;&gt;원시자료형&lt;/h3&gt;
&lt;blockquote&gt;
  &lt;p&gt;JavaScript에서 원자시료형은 객체가 아니면서 method를 갖지 않는 6개의 타입
string, number, &lt;del&gt;bigint&lt;/del&gt;, boolean, undefined, &lt;del&gt;symbol&lt;/del&gt;, (null) (취소선은 자주 쓰지 않는 타입)&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;원시자료형은 모두 “하나”의 정보, 즉 데이터를 담고 있다.&lt;br /&gt;
==데이터 보관함 한 칸에 하나의 데이터만== 넣을 수 있는 “원시적인”방식.&lt;br /&gt;
그래서 원시자료형이 담기는 보관함의 크기는 고정하는 것이 합당하다. (데이터 크기를 예측 가능하기 때문)&lt;br /&gt;
&lt;strong&gt;&lt;span style=&quot;color: tomato; font-type: 1.3rem&quot;&gt;=&amp;gt; 변수에는 하나의 데이터만 담는다&lt;/span&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;원시 자료형은 값 자체에 대한 변경이 불가능하지만 변수에 다른 데이터를 할당할 수는 있다.&lt;/p&gt;

&lt;h3 id=&quot;참조자료형&quot;&gt;참조자료형&lt;/h3&gt;
&lt;blockquote&gt;
  &lt;p&gt;원시 자료형이 아닌 것은 모두 참조 자료형이다. (배열, 객체 함수가 대표적이다.)
참조 자료형에는 하나가 아닌 여러 개의 데이터가 담긴다.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;변수에는 참조 자료형이 저장되는 데이터 보관함을 찾아갈 수 있는 ==주소==가 담겨있고 주소가 가리키는 곳에 위치한 데이터 보관함의 사이즈는 동적으로 변한다.&lt;/p&gt;

&lt;p&gt;&lt;span style=&quot;font-size: 1.2rem&quot;&gt;:smirk: 정리하면&lt;/span&gt;
원시 자료형이 할당될 땐 변수에 값 자체가 담기고,&lt;br /&gt;
참조 자료형이 할당될 땐 보관함으 주소가 담긴다.&lt;/p&gt;

&lt;p&gt;참조자료형은 기존에 고정된 크기의 보관함이 아니라, 동적으로 크기가 변화는 특별한 보관함을 사용할 수 있다.&lt;/p&gt;

&lt;h2 id=&quot;스코프&quot;&gt;스코프&lt;/h2&gt;
&lt;p&gt;스코프는 ‘변수 접근 규칙에 따른 유효 범위’이다.&lt;/p&gt;

&lt;h3 id=&quot;스코프의-주요-규칙&quot;&gt;스코프의 주요 규칙&lt;/h3&gt;
&lt;ol&gt;
  &lt;li&gt;안쪽 스코프에서 바깥쪽 스코프로는 접근할 수 있으나 반대는 불가능&lt;/li&gt;
  &lt;li&gt;스코프는 중첩이 가능하다.
    &lt;ol&gt;
      &lt;li&gt;가장 바깥쪽 스코프는 &lt;strong&gt;전역 스코프&lt;/strong&gt;라고 부른다.&lt;/li&gt;
      &lt;li&gt;전역이 아닌 다른 스코프는 전부 &lt;strong&gt;지역 스코프&lt;/strong&gt;라고 부른다.
        &lt;ol&gt;
          &lt;li&gt;지역 스코프에 선언한 변수는 &lt;strong&gt;지역 변수&lt;/strong&gt;, 전역 스코프에서 선언한 변수는 &lt;strong&gt;전역변수&lt;/strong&gt;라고 부른다.
&lt;img src=&quot;/assets/img/2023-10-13/scope.png&quot; alt=&quot;scope1&quot; /&gt;&lt;/li&gt;
        &lt;/ol&gt;
      &lt;/li&gt;
    &lt;/ol&gt;
  &lt;/li&gt;
  &lt;li&gt;지역 변수는 전역변수보다 우선순위가 높다.&lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;스코프와-변수-선언&quot;&gt;스코프와 변수 선언&lt;/h3&gt;
&lt;p&gt;스코프는 두 가지 종류가 있다.&lt;br /&gt;
블록스코프 : 중괄호를 기준으로 번위가 구분된다. (단, 화살표함수는 블록스코프다.)&lt;br /&gt;
함수스코프 : function keyword가 등장하는 함수 선언식 및 함수 표현식&lt;/p&gt;

&lt;h4 id=&quot;var로-변수를-선언하면&quot;&gt;var로 변수를 선언하면?&lt;/h4&gt;
&lt;div class=&quot;language-javascript highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;k&quot;&gt;for&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kd&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;i&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;i&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;5&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;++&amp;gt;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;nx&quot;&gt;console&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;})&lt;/span&gt;
&lt;span class=&quot;nx&quot;&gt;console&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;iis i:&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;= 블록범위를 벗어나도 변수 i 에 접근이 가능하다.&lt;br /&gt;
&lt;strong&gt;&lt;span style=&quot;color: tomato; font-size: 1.2rem&quot;&gt;var키워드는 블록 스코프를 무시하고 함수 스코프만 따른다.&lt;/span&gt;&lt;/strong&gt; (단, 화살표함수의 블록스코프는 제외)&lt;/p&gt;

&lt;p&gt;그러나 위처럼 예외의 예외가 있는 등 사용시 고려해야할 점이 많으므로,&lt;br /&gt;
블록 단위로 스코프를 구분했을 때 훨씬 더 예측 가능한 코드를 작성할 수 있는 ‘let’키워드의 사용을 권장한다.&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;var보다 let을 더 권장하는 또 다른 이유
    &lt;ul&gt;
      &lt;li&gt;var키워드는 재선언을 해도 에러가 나지 않지만 let 키워드는 에러가 나 재선언을 방지한다. (재선언 남발하면 뭐가 뭔지 알 수 없어 코드작성에 혼란을 가져다 줄 수 있다.)&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;또 다른 변수 선언 키워드 const
    &lt;ul&gt;
      &lt;li&gt;변하지 않는 값. 상수를 정의할 때 사용.&lt;/li&gt;
      &lt;li&gt;값의 재할당이 불가하여 의도치 않은 값의 변경을 막을 수 있다.&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;img src=&quot;/assets/img/2023-10-13/scope2.png&quot; alt=&quot;scope2&quot; /&gt;&lt;/p&gt;

&lt;h3 id=&quot;변수-선언에서-주의할-점&quot;&gt;변수 선언에서 주의할 점.&lt;/h3&gt;
&lt;ol&gt;
  &lt;li&gt;var로 선언된 전역 변수 및 전역 함수는 window 객체에 속하게 된다.&lt;/li&gt;
&lt;/ol&gt;

&lt;div class=&quot;language-javascript highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;  &lt;span class=&quot;kd&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;myName&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;jscho&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;nx&quot;&gt;console&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;window&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;myName&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;// jscho&lt;/span&gt;

  &lt;span class=&quot;kd&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;func&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(){&lt;/span&gt;
    &lt;span class=&quot;nx&quot;&gt;console&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;bar&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
  &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;

  &lt;span class=&quot;nx&quot;&gt;console&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;foo&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;===&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;window&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;foo&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;//true&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;ol&gt;
  &lt;li&gt;전역 변수에 너무 많은 변수를 선언하지 말 것.
    &lt;ol&gt;
      &lt;li&gt;편리하지만 다른 함수 혹은 로직에 의해 의도치 않은 변경 발생할 수 있다. (side effect)&lt;/li&gt;
    &lt;/ol&gt;
  &lt;/li&gt;
  &lt;li&gt;let, const를 주로 사용하라
    &lt;ol&gt;
      &lt;li&gt;var는 블록 스코플르 무시하며 재선언을 해도 에러를 내지 않아 버그를 유발한다.&lt;/li&gt;
      &lt;li&gt;전역 변수를 var로 선언하면 window 기즌을 덮어씌워 내장 기능을 사용할 수 없게 만들 수 있다.&lt;/li&gt;
    &lt;/ol&gt;
  &lt;/li&gt;
  &lt;li&gt;선언 없는 변수 할당 금지
    &lt;ol&gt;
      &lt;li&gt;선언 키워드( var, let const)없이 변수를 할당하면 해당 변수는 var로 선언한 전역변수처럼 취급된다.
        &lt;ol&gt;
          &lt;li&gt;‘use strict’ (엄격모드)를 사용해 보다 엄격하게 에러를 판단할 수 있다. (파일 상단에 입력)&lt;/li&gt;
        &lt;/ol&gt;
      &lt;/li&gt;
    &lt;/ol&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;클로저&quot;&gt;클로저&lt;/h2&gt;
&lt;h3 id=&quot;클로저의-특징&quot;&gt;클로저의 특징&lt;/h3&gt;
&lt;ol&gt;
  &lt;li&gt;함수를 리턴한다.&lt;/li&gt;
  &lt;li&gt;내부 함수는 외부 함수에 선언된 변수에 접근 가능.
    &lt;blockquote&gt;
      &lt;p&gt;함수를 리턴하는 함수&lt;/p&gt;
    &lt;/blockquote&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;div class=&quot;language-javascript highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;  &lt;span class=&quot;kd&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;adder&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;x&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;y&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;x&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;y&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;

  &lt;span class=&quot;kd&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;adder&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;y&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
      &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;x&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;y&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
  &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;

  &lt;span class=&quot;c1&quot;&gt;// 위, 아래의 adder 함수는 동일하게 작동한다.&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;클로저는 리턴하는 함수에 의해 스코프가 구분된다.&lt;br /&gt;
클로저의 핵심은 스코프를 이용해 변수의 접근 범위를 닫는 데에 있다. (closure)&lt;br /&gt;
중요한 건, 변수가 선언된 곳.&lt;/p&gt;

&lt;h3 id=&quot;클로저의-활용&quot;&gt;클로저의 활용&lt;/h3&gt;
&lt;p&gt;일반적인 함수는, 함수 실행이 끝나고 나면 함수 내부의 변수를 사용할 수 없다.&lt;br /&gt;
그러나 클로저는 외부 함수의 실행이 끝나도, 오부 함수 내 변수가 메모리 상에 저장된다.&lt;/p&gt;

&lt;p&gt;예시를 보자&lt;/p&gt;
&lt;h4 id=&quot;1-데이터를-보존하는-클로저-함수&quot;&gt;1. 데이터를 보존하는 클로저 함수&lt;/h4&gt;
&lt;div class=&quot;language-javascript highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kd&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;tagMaker&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;tag&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;content&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;`&amp;lt;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;${&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;tag&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;${&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;content&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;${&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;tag&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&amp;gt;`&lt;/span&gt;

&lt;span class=&quot;kd&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;divMaker&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;tagMaker&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;div&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;//`&amp;lt;div&amp;gt;${content}&amp;lt;/div&amp;gt;`&lt;/span&gt;

&lt;span class=&quot;nx&quot;&gt;divMaker&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;hello&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;//`&amp;lt;div&amp;gt;hello&amp;lt;/div&amp;gt;`&lt;/span&gt;
&lt;span class=&quot;nx&quot;&gt;divMaker&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;codestates&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;// `&amp;lt;div&amp;gt;codestates&amp;lt;/div&amp;gt;`&lt;/span&gt;

&lt;span class=&quot;kd&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;anchorMaker&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;tagMaker&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;//`&amp;lt;a&amp;gt;${content}&amp;lt;/a&amp;gt;`&lt;/span&gt;

&lt;span class=&quot;nx&quot;&gt;anchorMaker&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;go&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;// `&amp;lt;a&amp;gt;go&amp;lt;/a&amp;gt;`&lt;/span&gt;
&lt;span class=&quot;nx&quot;&gt;anchorMaker&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;urclass&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;// `&amp;lt;a&amp;gt;urclass&amp;lt;/a&amp;gt;`&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h4 id=&quot;2-클로저-모듈-패턴&quot;&gt;2. 클로저 모듈 패턴&lt;/h4&gt;
&lt;p&gt;클로저를 이용해 내부 함수를 하나만 리턴하지 않고 객체에 담아 여러 개 리턴하게 만든다.&lt;/p&gt;

&lt;div class=&quot;language-javascript highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kd&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;makeCounter&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;kd&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;value&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;

  &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;na&quot;&gt;increase&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
      &lt;span class=&quot;nx&quot;&gt;value&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;value&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;},&lt;/span&gt;
    &lt;span class=&quot;na&quot;&gt;decrease&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
      &lt;span class=&quot;nx&quot;&gt;value&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;value&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;},&lt;/span&gt;
    &lt;span class=&quot;na&quot;&gt;getValue&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;value&lt;/span&gt;
  &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;kd&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;counter1&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;makeCounter&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;();&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;//counter1은 객체이다.&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;Q. makeCounter함수를 바꾸지 않고 value란 변수에 값을 새로 할당할 방법이 있을까?&lt;br /&gt;
A. NO. 직접 수정은 불가능하다. (-&amp;gt;  캡슐화라고 한다.)리턴하는 객체가 제공하는 메서드를 통해 간접 조작은 가능.&lt;/p&gt;

&lt;div class=&quot;language-javascript highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kd&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;counter1&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;makeCounter&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;();&lt;/span&gt;
&lt;span class=&quot;nx&quot;&gt;counter1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;increase&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;();&lt;/span&gt;
&lt;span class=&quot;nx&quot;&gt;counter1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;getValue&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;();&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;//1&lt;/span&gt;

&lt;span class=&quot;kd&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;counter2&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;makeCounter&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;();&lt;/span&gt;
&lt;span class=&quot;nx&quot;&gt;counter2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;decrease&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;();&lt;/span&gt;
&lt;span class=&quot;nx&quot;&gt;counter2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;getValue&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;();&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;//-1&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;counter1과 counter2는 각각의 값을 가지고 있다.&lt;br /&gt;
함수 사용성을 극대화하여 서로에게 영향을 끼치지 않고 각각의 값을 독립적으로 가질 수 있다.&lt;/p&gt;

&lt;p&gt;이와 같이 함수 하나를 완전히 독립적인 부품 형태로 분리하는 것&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;span style=&quot;color: tomato; font-size: 1.2rem&quot;&gt;=&amp;gt; 모듈화&lt;/span&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;클로저는 모듈화에 유리하다.&lt;/p&gt;

&lt;h2 id=&quot;es6-주요문법&quot;&gt;ES6 주요문법&lt;/h2&gt;

&lt;h3 id=&quot;spread--rest&quot;&gt;spread / rest&lt;/h3&gt;
&lt;ol&gt;
  &lt;li&gt;spread문법
배열을 풀어서 인자로 전달하거나 배열을 풀어 각각의 요소로 넣을 때 사용한다.&lt;br /&gt;
spread문법은 배열에서 잘 쓰인다.&lt;br /&gt;
spread문법은 immutable(변경하지 않는다)하다. (필요하면 값 재할당을 해야함)&lt;/li&gt;
&lt;/ol&gt;

&lt;div class=&quot;language-javascript highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kd&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;sum&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;y&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;z&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;){&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;x&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;y&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;z&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;kd&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;numbers&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;];&lt;/span&gt;

&lt;span class=&quot;nx&quot;&gt;sum&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(...&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;numbers&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;///6&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;//배열을 풀어 각각의 요소로 넣었다.&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;ol&gt;
  &lt;li&gt;rest문법
파라미터를 배열의 형태로 받아서 사용할 수 있다. (파라미터 개수가 가변적일 때 유용하다.)&lt;/li&gt;
&lt;/ol&gt;

&lt;div class=&quot;language-javascript highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kd&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;sum&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(...&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;theArgs&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;){&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;the&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;Args&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;reduce&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;((&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;pre&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;cur&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;pre&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;cur&lt;/span&gt;
  &lt;span class=&quot;p&quot;&gt;});&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;nx&quot;&gt;sum&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;//6&lt;/span&gt;
&lt;span class=&quot;nx&quot;&gt;sum&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;4&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;//10&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;//파라미터를 배혈의 형태로 받아 사용했다.&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;ol&gt;
  &lt;li&gt;응용
    &lt;ol&gt;
      &lt;li&gt;배열
        &lt;ol&gt;
          &lt;li&gt;배열 합치기&lt;/li&gt;
        &lt;/ol&gt;

        &lt;div class=&quot;language-javascript highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;  &lt;span class=&quot;kd&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;parts&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;shourders&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;knees&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;];&lt;/span&gt;
  &lt;span class=&quot;kd&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;lyrics&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;head&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;...&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;parts&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;and&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;toes&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;];&lt;/span&gt;

  &lt;span class=&quot;nx&quot;&gt;console&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;lyrics&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;//['head', 'shourders', 'knees', 'and', 'toes']&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;        &lt;/div&gt;

        &lt;ol&gt;
          &lt;li&gt;배열 복사&lt;/li&gt;
        &lt;/ol&gt;

        &lt;div class=&quot;language-javascript highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;  &lt;span class=&quot;kd&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;arr&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;];&lt;/span&gt;
  &lt;span class=&quot;kd&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;arr2&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[...&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;arr&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;];&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;// arr.slice()와 유사하다.&lt;/span&gt;
        
  &lt;span class=&quot;nx&quot;&gt;console&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;arr2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;// [1, 2, 3]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;        &lt;/div&gt;
      &lt;/li&gt;
      &lt;li&gt;객체&lt;/li&gt;
    &lt;/ol&gt;

    &lt;div class=&quot;language-javascript highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;   &lt;span class=&quot;kd&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;obj1&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;foo&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;bar&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;42&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;};&lt;/span&gt;
   &lt;span class=&quot;kd&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;obj2&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;foo&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;baz&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;y&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;13&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;};&lt;/span&gt;

   &lt;span class=&quot;kd&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;clonedObj&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{...&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;obj1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;};&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;//{foo: 'bar', x: 42}&lt;/span&gt;
   &lt;span class=&quot;kd&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;mergedObj&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{...&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;obj1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;...&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;obj2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;};&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;//{foo: 'bax', x: 42, y: 13} &lt;/span&gt;
   &lt;span class=&quot;c1&quot;&gt;//foo의 값만 obj2의 값으로 덮어씌워지고 나머지는 합쳐진다.&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;    &lt;/div&gt;

    &lt;ol&gt;
      &lt;li&gt;함수에서 나머지 파라미터 받아오기&lt;/li&gt;
    &lt;/ol&gt;

    &lt;div class=&quot;language-javascript highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;   &lt;span class=&quot;kd&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;myFun&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;...&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;manyMoreArgs&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;){&lt;/span&gt;
     &lt;span class=&quot;nx&quot;&gt;console&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
     &lt;span class=&quot;nx&quot;&gt;console&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
     &lt;span class=&quot;nx&quot;&gt;console&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;manyMoreArgs&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;manyMoreArgs&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
   &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;

   &lt;span class=&quot;nx&quot;&gt;myFun&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;one&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;two&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;three&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;four&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;five&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;six&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
   &lt;span class=&quot;c1&quot;&gt;//a one&lt;/span&gt;
   &lt;span class=&quot;c1&quot;&gt;//b two&lt;/span&gt;
   &lt;span class=&quot;c1&quot;&gt;//manyMoreArgs ['three', 'four', 'five', 'six']&lt;/span&gt;
      
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;    &lt;/div&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;구조분해할당&quot;&gt;구조분해할당&lt;/h3&gt;
&lt;p&gt;구조분해할당은 spread문법을 이용해 값을 해체한 후, 개별 값을 변수에 새로 할당하는 과정이다.&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;분해 후 새 변수 할당
    &lt;ol&gt;
      &lt;li&gt;배열
        &lt;div class=&quot;language-javascript highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kd&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;...&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;rest&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;10&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;20&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;30&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;40&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;50&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;];&lt;/span&gt;
      
&lt;span class=&quot;nx&quot;&gt;console&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;//10&lt;/span&gt;
&lt;span class=&quot;nx&quot;&gt;console&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;//20&lt;/span&gt;
&lt;span class=&quot;nx&quot;&gt;console&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;rest&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;//[30, 40, 50]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;        &lt;/div&gt;
      &lt;/li&gt;
      &lt;li&gt;객체
        &lt;div class=&quot;language-javascript highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kd&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;...&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;rest&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;10&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;20&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;c&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;30&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;d&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;40&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;nx&quot;&gt;console&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;//10&lt;/span&gt;
&lt;span class=&quot;nx&quot;&gt;console&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;//20&lt;/span&gt;
&lt;span class=&quot;nx&quot;&gt;console&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;rest&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;//{c: 30, d: 40}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;        &lt;/div&gt;
      &lt;/li&gt;
    &lt;/ol&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;객체에서 구조 분해 할당을 사용하는 경우, 선언키워드와 함께 사용하지 않으면 에러가 발생할 수 있다.&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;예제: 함수에서 객체 분해하기&lt;/li&gt;
&lt;/ol&gt;

&lt;div class=&quot;language-javascript highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kd&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;whois&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;({&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;displayName&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;displayName&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;fullName&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;firstName&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;}}){&lt;/span&gt;
  &lt;span class=&quot;nx&quot;&gt;console&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;displayName&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt; is &lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;kd&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;user&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;na&quot;&gt;id&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;42&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
  &lt;span class=&quot;na&quot;&gt;displayName&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;jdoe&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
  &lt;span class=&quot;na&quot;&gt;fullName&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
      &lt;span class=&quot;na&quot;&gt;firstName&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;John&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
      &lt;span class=&quot;na&quot;&gt;lastName&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;Doe&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;
  &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;};&lt;/span&gt;

&lt;span class=&quot;nx&quot;&gt;whois&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;user&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;//jdoe is John&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;</content><author><name>Subin Cho</name><email>lunadein2022@gmail.com</email></author><category term="Study" /><category term="study" /><category term="javascript" /><summary type="html"></summary><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://lunadein2022.github.io/assets/img/thumbnail/js.png" /><media:content medium="image" url="https://lunadein2022.github.io/assets/img/thumbnail/js.png" xmlns:media="http://search.yahoo.com/mrss/" /></entry><entry><title type="html">[HTML, CSS] Layout &amp;amp; Wireframe</title><link href="https://lunadein2022.github.io/study/basic1-3_1.html" rel="alternate" type="text/html" title="[HTML, CSS] Layout &amp;amp; Wireframe" /><published>2023-01-05T00:00:00+09:00</published><updated>2023-01-05T00:00:00+09:00</updated><id>https://lunadein2022.github.io/study/basic1-3_1</id><content type="html" xml:base="https://lunadein2022.github.io/study/basic1-3_1.html">&lt;ul id=&quot;markdown-toc&quot;&gt;
  &lt;li&gt;&lt;a href=&quot;#와이어프레임wireframe&quot; id=&quot;markdown-toc-와이어프레임wireframe&quot;&gt;와이어프레임(Wireframe)&lt;/a&gt;    &lt;ul&gt;
      &lt;li&gt;&lt;a href=&quot;#목업mock-up&quot; id=&quot;markdown-toc-목업mock-up&quot;&gt;목업(Mock-up)&lt;/a&gt;        &lt;ul&gt;
          &lt;li&gt;&lt;a href=&quot;#와이어프레임의-목적&quot; id=&quot;markdown-toc-와이어프레임의-목적&quot;&gt;와이어프레임의 목적?&lt;/a&gt;&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;#와이어프레임-그리기&quot; id=&quot;markdown-toc-와이어프레임-그리기&quot;&gt;와이어프레임 그리기&lt;/a&gt;        &lt;ul&gt;
          &lt;li&gt;&lt;a href=&quot;#html-구성하기&quot; id=&quot;markdown-toc-html-구성하기&quot;&gt;HTML 구성하기&lt;/a&gt;&lt;/li&gt;
          &lt;li&gt;&lt;a href=&quot;#레이아웃-리셋&quot; id=&quot;markdown-toc-레이아웃-리셋&quot;&gt;레이아웃 리셋&lt;/a&gt;&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;
&lt;!--more--&gt;

&lt;h2 id=&quot;와이어프레임wireframe&quot;&gt;와이어프레임(Wireframe)&lt;/h2&gt;
&lt;p&gt;웹 또는 애플리케이션을 개발할 때 &lt;strong&gt;레이아웃의 뼈대를 그리는&lt;/strong&gt; 단계 -&amp;gt; 와이어프레임&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;단순한 선이나 도형으로 웹이나 앱의 인터페이스를 시각적으로 묘사한 것. (화면의 영역을 구분함)&lt;/li&gt;
  &lt;li&gt;아주 단순하게 레이아웃과 제품의 구조를 보여주는 용도.
    &lt;ul&gt;
      &lt;li&gt;전환 효과, 애니메이션, 사용자 테스트 같은 스타일링 요소나 UX까지 표현하는 것이 아님&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;목업mock-up&quot;&gt;목업(Mock-up)&lt;/h3&gt;
&lt;p&gt;‘실물 크기의 모형’이라는 뜻을 가진 목업.&lt;br /&gt;
무형의 웹, 앱에서는 &lt;strong&gt;&lt;span style=&quot;font-size: 1.2rem; color: tomato&quot;&gt;실제 제품이 작동하는 모습과 동일하게 HTML문서를 작성하여&lt;/span&gt;&lt;/strong&gt;목업을 만든다&lt;/p&gt;

&lt;h4 id=&quot;와이어프레임의-목적&quot;&gt;와이어프레임의 목적?&lt;/h4&gt;
&lt;p&gt;HTML문서작성을 통해 영역을 구분하고 구조를 그려보지 않으면 JavaScript를 적용한 완성본이 어떤 형태를 가질지 상상하기 어려워진다.&lt;/p&gt;

&lt;h3 id=&quot;와이어프레임-그리기&quot;&gt;와이어프레임 그리기&lt;/h3&gt;
&lt;h4 id=&quot;html-구성하기&quot;&gt;HTML 구성하기&lt;/h4&gt;
&lt;p&gt;대부분의 경우 콘텐츠의 흐름은 좌에서 우, 위에서 아래로 흐른다.&lt;br /&gt;
CSS로 화면을 구분할 때는 수직 분할과 수평 분할을 차례대로 적용해 콘텐츠의 흐름을 따라 작업을 진행한다.&lt;/p&gt;

&lt;h4 id=&quot;레이아웃-리셋&quot;&gt;레이아웃 리셋&lt;/h4&gt;
&lt;p&gt;HTML문서는 기본적인 스타일을 가지고 있다. -&amp;gt; 기본 스타일이 레이아웃잡는데 방해가 될 때가 있다.&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;박스의 시작을 정확히 (0, 0)의 위치에서 시작하고 싶은데 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;body&lt;/code&gt;요소가 가진 기본 스타일에 약간의 여백이 있다.&lt;/li&gt;
  &lt;li&gt;width, height 계산이 여백을 포함하지 않아 계산이 어렵다.&lt;/li&gt;
  &lt;li&gt;브라우저마다 여백이나 글꼴과 같은 기본 스타일이 다르다&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;이럴 때는 아래의 코드를 CSS에 적고 시작하자.&lt;/p&gt;

&lt;div class=&quot;language-css highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;nl&quot;&gt;box-sizing&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;border-box&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;nt&quot;&gt;body&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;nl&quot;&gt;margin&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;m&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;nl&quot;&gt;padding&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;m&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;</content><author><name>Subin Cho</name><email>lunadein2022@gmail.com</email></author><category term="Study" /><category term="study" /><category term="javascript" /><summary type="html"></summary><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://lunadein2022.github.io/assets/img/thumbnail/html,css.png" /><media:content medium="image" url="https://lunadein2022.github.io/assets/img/thumbnail/html,css.png" xmlns:media="http://search.yahoo.com/mrss/" /></entry><entry><title type="html">[CSS] Flexbox</title><link href="https://lunadein2022.github.io/study/basic1-3_2.html" rel="alternate" type="text/html" title="[CSS] Flexbox" /><published>2023-01-05T00:00:00+09:00</published><updated>2023-01-05T00:00:00+09:00</updated><id>https://lunadein2022.github.io/study/basic1-3_2</id><content type="html" xml:base="https://lunadein2022.github.io/study/basic1-3_2.html">&lt;ul id=&quot;markdown-toc&quot;&gt;
  &lt;li&gt;&lt;a href=&quot;#flexbox&quot; id=&quot;markdown-toc-flexbox&quot;&gt;Flexbox?&lt;/a&gt;    &lt;ul&gt;
      &lt;li&gt;&lt;a href=&quot;#부모요소에-적용하는-flexbox-속성&quot; id=&quot;markdown-toc-부모요소에-적용하는-flexbox-속성&quot;&gt;부모요소에 적용하는 Flexbox 속성?&lt;/a&gt;        &lt;ul&gt;
          &lt;li&gt;&lt;a href=&quot;#1-flexbox-direction--정렬-축-정하기&quot; id=&quot;markdown-toc-1-flexbox-direction--정렬-축-정하기&quot;&gt;1. flexbox-direction : 정렬 축 정하기&lt;/a&gt;&lt;/li&gt;
          &lt;li&gt;&lt;a href=&quot;#2-flex-wrap--줄-바꿈-설정하기&quot; id=&quot;markdown-toc-2-flex-wrap--줄-바꿈-설정하기&quot;&gt;2. flex-wrap : 줄 바꿈 설정하기&lt;/a&gt;&lt;/li&gt;
          &lt;li&gt;&lt;a href=&quot;#3-justify-content-축-수평-방향-정렬&quot; id=&quot;markdown-toc-3-justify-content-축-수평-방향-정렬&quot;&gt;3. justify-content: 축 수평 방향 정렬&lt;/a&gt;&lt;/li&gt;
          &lt;li&gt;&lt;a href=&quot;#4-align-items-축-수직-방향-정렬&quot; id=&quot;markdown-toc-4-align-items-축-수직-방향-정렬&quot;&gt;4. align-items: 축 수직 방향 정렬&lt;/a&gt;&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;#자식요소에-적용하는-flexbox-속성&quot; id=&quot;markdown-toc-자식요소에-적용하는-flexbox-속성&quot;&gt;자식요소에 적용하는 Flexbox 속성?&lt;/a&gt;        &lt;ul&gt;
          &lt;li&gt;&lt;a href=&quot;#1-flex-속성의-값&quot; id=&quot;markdown-toc-1-flex-속성의-값&quot;&gt;1. flex 속성의 값&lt;/a&gt;&lt;/li&gt;
          &lt;li&gt;&lt;a href=&quot;#2-grow-얼마나-늘어날까&quot; id=&quot;markdown-toc-2-grow-얼마나-늘어날까&quot;&gt;2. grow: 얼마나 늘어날까?&lt;/a&gt;&lt;/li&gt;
          &lt;li&gt;&lt;a href=&quot;#3-shrink-얼마나-줄어들까&quot; id=&quot;markdown-toc-3-shrink-얼마나-줄어들까&quot;&gt;3. shrink: 얼마나 줄어들까?&lt;/a&gt;&lt;/li&gt;
          &lt;li&gt;&lt;a href=&quot;#4-basis-기본-크기는-얼마일까&quot; id=&quot;markdown-toc-4-basis-기본-크기는-얼마일까&quot;&gt;4. basis: 기본 크기는 얼마일까?&lt;/a&gt;&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;!--more--&gt;

&lt;blockquote&gt;
  &lt;p&gt;Flex(Flexible)는 “잘 구부러지는, 유연한”이라는 뜻이다.
Flexbox는 박스를 유연하게 늘리거나 줄여 레이아웃을 잡는방법.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2 id=&quot;flexbox&quot;&gt;Flexbox?&lt;/h2&gt;
&lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;display: flex&lt;/code&gt;는 부모 박스 요소에 적용해, 자식 박스의 방향과 크기를 결정하는 레이아웃 구성 방법.&lt;br /&gt;
flexbox의 속성들을 활용해 &lt;strong&gt;요소의 정렬&lt;/strong&gt;, &lt;strong&gt;요소가 차지하는 공간&lt;/strong&gt;을 설정해줄 수 있다.&lt;/p&gt;

&lt;h3 id=&quot;부모요소에-적용하는-flexbox-속성&quot;&gt;부모요소에 적용하는 Flexbox 속성?&lt;/h3&gt;
&lt;p&gt;Flexbox의 부모요소에 적용해야하는 속성은 자식 요소들의 &lt;strong&gt;‘정렬’&lt;/strong&gt;과 관련이 있다.&lt;/p&gt;

&lt;h4 id=&quot;1-flexbox-direction--정렬-축-정하기&quot;&gt;1. flexbox-direction : 정렬 축 정하기&lt;/h4&gt;
&lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;flex-direction&lt;/code&gt;속성은 자식 요소들을 정렬할 정렬 축을 정한다.&lt;br /&gt;
아무 설정 없을 시, 기본값은 가로정렬이다. (row)&lt;/p&gt;

&lt;div class=&quot;language-css highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nt&quot;&gt;main&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;nl&quot;&gt;display&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;flex&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;nl&quot;&gt;flex-direction&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;row&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;&lt;img src=&quot;/assets/img/2023-01-05/flexbox_1.gif&quot; alt=&quot;flexbox&quot; /&gt;&lt;/p&gt;

&lt;h4 id=&quot;2-flex-wrap--줄-바꿈-설정하기&quot;&gt;2. flex-wrap : 줄 바꿈 설정하기&lt;/h4&gt;
&lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;flex-wrap&lt;/code&gt;속성은 하위 요소들의 크기가 상위 요소의 크기를 넘으면 자동 줄 바꿈을 할 것인지 정한다. 기본값은 &lt;strong&gt;줄 바꿈을 하지 않는다.&lt;/strong&gt;&lt;/p&gt;

&lt;div class=&quot;language-css highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nt&quot;&gt;main&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;nl&quot;&gt;display&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;flex&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;nl&quot;&gt;flex-wrap&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;nowrap&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;&lt;img src=&quot;/assets/img/2023-01-05/flexbox_2.png&quot; alt=&quot;flexbox_2&quot; /&gt;&lt;/p&gt;

&lt;h4 id=&quot;3-justify-content-축-수평-방향-정렬&quot;&gt;3. justify-content: 축 수평 방향 정렬&lt;/h4&gt;
&lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;justify-content&lt;/code&gt;속성은 자식 요소들의 수평 방향으로 어떻게 정렬할 것인지 정한다.&lt;br /&gt;
요소들이 가로로 정렬되어 있다면 가로로 어떻게 정렬할 것인지,&lt;br /&gt;
요소들이 세로로 정렬되어 있다면 세로로 어떻게 정렬할 것인지 정하는 속성이다.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/img/2023-01-05/flexbox_3.png&quot; alt=&quot;flexbox_3&quot; /&gt;&lt;/p&gt;

&lt;p&gt;주요 속성값으로는 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;flex-start&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;flex-end&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;center&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;space-betwee&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;space-around&lt;/code&gt;가 있다.&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;flex-direction: row&lt;/code&gt;인 경우
&lt;img src=&quot;/assets/img/2023-01-05/flexbox_4.png&quot; alt=&quot;flexbox_4&quot; /&gt;&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;flex-direction: column&lt;/code&gt;인 경우
&lt;img src=&quot;/assets/img/2023-01-05/flexbox_5.png&quot; alt=&quot;flexbox_5&quot; /&gt;&lt;/p&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;4-align-items-축-수직-방향-정렬&quot;&gt;4. align-items: 축 수직 방향 정렬&lt;/h4&gt;
&lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;align-items&lt;/code&gt;속성은 자식 요소들을 축의 수직 방향으로 어떻게 정렬할 것인지 정한다.&lt;br /&gt;
요소들이 &lt;strong&gt;가로&lt;/strong&gt; 정렬되어 있다면 &lt;strong&gt;세로&lt;/strong&gt; 방향으로 어떻게 정렬할 것인지&lt;br /&gt;
요소들이 &lt;strong&gt;세로&lt;/strong&gt; 정렬되어 있다면 &lt;strong&gt;가로&lt;/strong&gt; 방향으로 어떻게 정렬할 것인지 정하는 속성이다.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/img/2023-01-05/flexbox_6.png&quot; alt=&quot;flexbox_6&quot; /&gt;&lt;/p&gt;

&lt;p&gt;주요 속성값으로는 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;stretch&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;flex-start&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;flex-end&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;center&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;baseline&lt;/code&gt;이 있다.&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;flex-direction: row&lt;/code&gt;인 경우
&lt;img src=&quot;/assets/img/2023-01-05/flexbox_7.png&quot; alt=&quot;flexbox_7&quot; /&gt;&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;flex-direction: column&lt;/code&gt;인 경우
&lt;img src=&quot;/assets/img/2023-01-05/flexbox_8.png&quot; alt=&quot;flexbox_8&quot; /&gt;&lt;/p&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;자식요소에-적용하는-flexbox-속성&quot;&gt;자식요소에 적용하는 Flexbox 속성?&lt;/h3&gt;
&lt;p&gt;Flexbox의 자식요소에 적용해야하는 속성은 요소가 차지하는 &lt;strong&gt;‘공간’&lt;/strong&gt;과 관련이 있다.&lt;/p&gt;

&lt;h4 id=&quot;1-flex-속성의-값&quot;&gt;1. flex 속성의 값&lt;/h4&gt;
&lt;p&gt;flex속성에는 세 가지 값을 지정해줄 수 있다.&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;grow (팽창 지수) : 요소의 크기가 늘어나야 할 때, 얼마나 늘어날 것인가&lt;/li&gt;
  &lt;li&gt;shrink (수축 지수) : 요소의 크기가 줄어들어야 할 때, 얼마나 줄어들 것인가&lt;/li&gt;
  &lt;li&gt;basis (기본 크기) : 늘어나고 줄어드는 것과 상관없이 요소의 기본 크기는 얼마인가&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;자식 요소에 flex 속성을 따로 설정하지 않았을 때의 기본값은 다음과 같으며 왼쪽에서 오른쪽으로 콘텐츠의 크기만큼 배치된다.&lt;/p&gt;

&lt;div class=&quot;language-css highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nt&quot;&gt;flex&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;err&quot;&gt;0&lt;/span&gt; &lt;span class=&quot;err&quot;&gt;1&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;auto&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;

&lt;span class=&quot;c&quot;&gt;/* 
flex: grow shrink basis;
*/&lt;/span&gt;

&lt;span class=&quot;nt&quot;&gt;flex-grow&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;err&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;nt&quot;&gt;flex-shrink&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;err&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;nt&quot;&gt;flex-basis&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;auto&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h4 id=&quot;2-grow-얼마나-늘어날까&quot;&gt;2. grow: 얼마나 늘어날까?&lt;/h4&gt;
&lt;p&gt;&lt;strong&gt;&lt;span style=&quot;font-size: 1.2rem; color: tomato&quot;&gt;팽창지수는 공간 총합에서의 비율로 빈 공간을 자치하게 된다.&lt;/span&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;h4 id=&quot;3-shrink-얼마나-줄어들까&quot;&gt;3. shrink: 얼마나 줄어들까?&lt;/h4&gt;
&lt;p&gt;&lt;strong&gt;&lt;span style=&quot;font-size: 1.2rem; color: tomato&quot;&gt;수축지수는 grow와 반대로 설정한 비율만큼 박스크기가 작아진다.&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;
grow 속성과 함께 사용하는건 지양해야한다. 기본값은 1이다.&lt;/p&gt;

&lt;h4 id=&quot;4-basis-기본-크기는-얼마일까&quot;&gt;4. basis: 기본 크기는 얼마일까?&lt;/h4&gt;
&lt;p&gt;&lt;strong&gt;&lt;span style=&quot;font-size: 1.2rem; color: tomato&quot;&gt;기본크기는 자식박스가 grow, shrink에 의해 변하기 전까지는 기본크기다.&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;
flex-grow가 0일 때만, basis 크기를 지정하면 그 크기는 유지된다.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/img/2023-01-05/flexbox_9.gif&quot; alt=&quot;flexbox_9&quot; /&gt;&lt;/p&gt;

&lt;details&gt;
&lt;summary style=&quot;color: tomato; font-size: 1.2rem&quot;&gt;Tip&lt;/summary&gt;
&lt;div&gt;

    &lt;ul&gt;
      &lt;li&gt;width와 flex-basis를 동시에 적용하는 경우, flex-basis가 우선됨.&lt;/li&gt;
      &lt;li&gt;콘텐츠가 많아 자식 박스가 넘치는 경우, width가 정확한 크기를 보장하지 않음.&lt;/li&gt;
      &lt;li&gt;(flex-basis를 사용하지 않는다면) 콘텐츠가 많아 자식 박스가 넘치는 경우를 대비해, width 대신 max-width를 쓸 수 있다.&lt;/li&gt;
    &lt;/ul&gt;

  &lt;/div&gt;
&lt;/details&gt;</content><author><name>Subin Cho</name><email>lunadein2022@gmail.com</email></author><category term="Study" /><category term="study" /><category term="javascript" /><summary type="html"></summary><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://lunadein2022.github.io/assets/img/thumbnail/css.png" /><media:content medium="image" url="https://lunadein2022.github.io/assets/img/thumbnail/css.png" xmlns:media="http://search.yahoo.com/mrss/" /></entry><entry><title type="html">[HTML] HTML에 대해 가장 먼저 알아야 할 것은?</title><link href="https://lunadein2022.github.io/study/basic1-2_1.html" rel="alternate" type="text/html" title="[HTML] HTML에 대해 가장 먼저 알아야 할 것은?" /><published>2023-01-04T00:00:00+09:00</published><updated>2023-01-04T00:00:00+09:00</updated><id>https://lunadein2022.github.io/study/basic1-2_1</id><content type="html" xml:base="https://lunadein2022.github.io/study/basic1-2_1.html">&lt;ul id=&quot;markdown-toc&quot;&gt;
  &lt;li&gt;&lt;a href=&quot;#html-기본-구조와-문법&quot; id=&quot;markdown-toc-html-기본-구조와-문법&quot;&gt;HTML 기본 구조와 문법&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#자주-사용하는-html요소&quot; id=&quot;markdown-toc-자주-사용하는-html요소&quot;&gt;자주 사용하는 HTML요소&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#시멘틱-요소&quot; id=&quot;markdown-toc-시멘틱-요소&quot;&gt;시멘틱 요소&lt;/a&gt;    &lt;ul&gt;
      &lt;li&gt;&lt;a href=&quot;#시멘틱-요소가-필요한-이유-및-상황&quot; id=&quot;markdown-toc-시멘틱-요소가-필요한-이유-및-상황&quot;&gt;시멘틱 요소가 필요한 이유 및 상황&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;#시멘틱-요소의-종류&quot; id=&quot;markdown-toc-시멘틱-요소의-종류&quot;&gt;시멘틱 요소의 종류&lt;/a&gt;&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#html에서-id-및-class-목적에-맞게-사용하기&quot; id=&quot;markdown-toc-html에서-id-및-class-목적에-맞게-사용하기&quot;&gt;HTML에서 id 및 class 목적에 맞게 사용하기&lt;/a&gt;    &lt;ul&gt;
      &lt;li&gt;&lt;a href=&quot;#태그와-id-class-선택자&quot; id=&quot;markdown-toc-태그와-id-class-선택자&quot;&gt;태그와 id, class 선택자&lt;/a&gt;&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;!--more--&gt;

&lt;p&gt;HTML(HyperText Markup Language)은 JavaScript와 같은 프로그래밍 언어가 아니라 웹 페이지의 뼈대를 구성하는 &lt;strong&gt;마크업 언어&lt;/strong&gt;이다. 그래서 HTML로 기본 뼈대를 만들고 CSS로 스타일을 입힌 다음 JavaScript로 동적으로 움직이게 만들 수 있다. 이와  같이 웹 페이지의 뼈대역할을 하는 HTML에 대해 알아보자.&lt;/p&gt;

&lt;h2 id=&quot;html-기본-구조와-문법&quot;&gt;HTML 기본 구조와 문법&lt;/h2&gt;
&lt;p&gt;HTML은 &lt;strong&gt;tag&lt;/strong&gt;들의 집합이다.&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;tag : 부등호(&amp;lt;&amp;gt;)로 묶인 HTML의 기본 구성 요소
```javascript&lt;/li&gt;
&lt;/ul&gt;
&lt;html&gt;
  &lt;head&gt;
    &lt;title&gt;&lt;/title&gt;
  &lt;/head&gt;
  &lt;body&gt;
    &lt;h1&gt;&lt;/h1&gt;
    &lt;div&gt;
      &lt;span&gt;&lt;/span&gt;
    &lt;/div&gt;
  &lt;/body&gt;
&lt;/html&gt;
&lt;p&gt;```&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;여는 태그 + 닫는 태그의 짝을 지어 작성한다. (&lt;tags&gt;: 여는태그, &lt;/tags&gt; : 닫는태그)&lt;/li&gt;
  &lt;li&gt;Self-Closing Tag : 태그 내부에 내용이 없다면 닫는 태그를 사용하지 않아도 된다. (&lt;tag&gt;&lt;/tag&gt;)&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;자주-사용하는-html요소&quot;&gt;자주 사용하는 HTML요소&lt;/h2&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt;태그&lt;/th&gt;
      &lt;th&gt;설명&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;div&lt;/td&gt;
      &lt;td&gt;Division&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;span&lt;/td&gt;
      &lt;td&gt;Span&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;img&lt;/td&gt;
      &lt;td&gt;Image&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;a&lt;/td&gt;
      &lt;td&gt;Link&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;ul &amp;amp; li&lt;/td&gt;
      &lt;td&gt;Unordered List &amp;amp; List Item&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;input&lt;/td&gt;
      &lt;td&gt;Input(Text, Radio, Checkbox)&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;textarea&lt;/td&gt;
      &lt;td&gt;Multi-line Text Input&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;button&lt;/td&gt;
      &lt;td&gt;Button&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;ul&gt;
  &lt;li&gt;div VS span
    &lt;ul&gt;
      &lt;li&gt;div태그는 한 줄을 차지한다.&lt;/li&gt;
      &lt;li&gt;span태그는 컨텐츠 크기만큼 공간을 차지한다.&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;img : &lt;strong&gt;src&lt;/strong&gt;속성으로 이미지 주소를 가져와 삽입한다. (닫는 태그 필요없음)&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;a : 링크 삽입 &lt;strong&gt;href&lt;/strong&gt;속성으로 링크 주소를 가져와 삽입한다.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;ul : unordered list -&amp;gt; 숫자로 순서를 지정하지 않는 리스트&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;ol : ordered list -&amp;gt; 숫자로 순서를 지정하는 리스트
    &lt;ul&gt;
      &lt;li&gt;ul, ol은 직계자식요소로 &lt;strong&gt;li&lt;/strong&gt;만 올 수 있다.&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;input, textarea : 다양한 입력폼이다. 아이디를 입력하거나 체크박스에 체크하는 등.
    &lt;ul&gt;
      &lt;li&gt;checkbox vs radio? : checkbox는 여러개 선택 가능하지만 radio는(&lt;strong&gt;name&lt;/strong&gt;이라는 속성으로 그룹설정시) 하나만 선택 가능하다.&lt;/li&gt;
      &lt;li&gt;textarea : 줄바꿈이 되는 입력폼&lt;/li&gt;
      &lt;li&gt;button : 클릭하면 상태가 변하는, 우리가 흔히 아는 그 버튼.&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;시멘틱-요소&quot;&gt;시멘틱 요소&lt;/h2&gt;
&lt;p&gt;시멘틱이란 ‘의미가 있는, 의미론적인’이라는 뜻으로, 의미를 가진 요소를 사용하는 방식을 추구하는 것이다.&lt;/p&gt;

&lt;h3 id=&quot;시멘틱-요소가-필요한-이유-및-상황&quot;&gt;시멘틱 요소가 필요한 이유 및 상황&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;모든 단락에 div만 사용한다면 나중에 수많은 div를 마주하게 되었을 때, 이게 어떤 내용을 담는 부분인지 구조적으로 파악하기 어렵고 혼란스러워질 것이다. (div를 하나하나 탐색하는 것보다 의미 있는 코드블록을 찾는 게 더 편리하고 요소 안에 채워질 데이터 유형을 예측하기 쉽다.)&lt;/li&gt;
  &lt;li&gt;검색 엔진이 시멘틱요소를 더 좋아한다. 즉, 시멘틱 요소에 담긴 의미에 따라 검색 결과에 따른 상위노출이 결정될 수 있다.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;시멘틱-요소의-종류&quot;&gt;시멘틱 요소의 종류&lt;/h3&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt;태그 이름&lt;/th&gt;
      &lt;th&gt;설명&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;article&lt;/td&gt;
      &lt;td&gt;독립적이고 자체 포함된 콘텐츠 지정&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;aside&lt;/td&gt;
      &lt;td&gt;본문의 주요 부분을 표시하고 남은 부분을 설명하는 요소, 특별한 일이 아니면 사이드바나 광고창 등 중요하지 않은 부분에 사용됨&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;footer&lt;/td&gt;
      &lt;td&gt;일반적으로 페이지나 해당 파트의 가장 아랫부분에 위치, 사이트의 라이센스, 주소 연락처 등이 있음&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;header&lt;/td&gt;
      &lt;td&gt;일반적으로 페이지나 해당 섹션의 가장 윗부분에 위치하며, 사이트의 제목이 보통 들어간다. 선택적으로 상단바나 검색창 등이 안에 들어갈 수 있다&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;nav&lt;/td&gt;
      &lt;td&gt;네비게이션(navigation)의 약자로, 일반적으로 상단바 등 사이트를 안내하는 요소에 사용됨. 보통은 안에 ul을 넣어 목록 형태로 사용&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;main&lt;/td&gt;
      &lt;td&gt;문서의 주된 콘텐츠 표시&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;h2 id=&quot;html에서-id-및-class-목적에-맞게-사용하기&quot;&gt;HTML에서 id 및 class 목적에 맞게 사용하기&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;&lt;span style=&quot;color: tomato; font-size: 24px&quot;&gt;id : 고유한 이름을 붙일 때&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;
변화가 없이 고정으로 고유한 영역에는 id로 이름을 붙인다.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;span style=&quot;color: royalblue; font-size: 24px&quot;&gt;class : 반복되는 영역을 유형별로 분류할 때&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;
반복되는 항목은 class로 지정한다. 같은 class값을 지정해줌으로서, 동일한 유형임을 알 수 있다.&lt;/p&gt;

&lt;h3 id=&quot;태그와-id-class-선택자&quot;&gt;태그와 id, class 선택자&lt;/h3&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt;HTML tag&lt;/th&gt;
      &lt;th&gt;Selector&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;‘&amp;lt;span id=”writing-section”’&amp;gt;&lt;/td&gt;
      &lt;td&gt;div#writing-section&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;‘&amp;lt;li class=”“comment”&amp;gt;’&lt;/td&gt;
      &lt;td&gt;li.comment&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;</content><author><name>Subin Cho</name><email>lunadein2022@gmail.com</email></author><category term="Study" /><category term="study" /><category term="javascript" /><summary type="html"></summary><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://lunadein2022.github.io/assets/img/thumbnail/html.png" /><media:content medium="image" url="https://lunadein2022.github.io/assets/img/thumbnail/html.png" xmlns:media="http://search.yahoo.com/mrss/" /></entry></feed>