textContent, innerText, innerHTML ๊ฐ„๋‹จ ๋น„๊ต(javascript)

์š”์†Œ์˜ ํ…์ŠคํŠธ๋ฅผ ๋‹ค๋ฃจ๋Š” textContent, innerText, innerHTML์˜ ์ฐจ์ด์ ๊ณผ ์œ ์˜ ์‚ฌํ•ญ

์š”์†Œ์— ์ ‘๊ทผํ•ด ๋ฐ์ดํ„ฐ๋ฅผ ์„ค์ •ํ•˜๊ฑฐ๋‚˜ ๊ฐ€์ ธ์˜ฌ ๋•Œ ์‚ฌ์šฉํ•˜๋Š” ํ”„๋กœํผํ‹ฐ์ธ textContent, innerText, innerHTML์— ๋Œ€ํ•ด ์•Œ์•„๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค.

<div id=1 onClick=(check(event))>click
    <div id=2>child1</div>
    <div id=3>child2
      <div id=4>grandchild</div>
    </div>
</div>

onClick ์ด๋ฒคํŠธ๋ฅผ ํ†ตํ•ด div์š”์†Œ์˜ ํ…์ŠคํŠธ์— ์ ‘๊ทผํ•  ๋•Œ ๊ฐ๊ฐ์˜ ํ”„๋กœํผํ‹ฐ๋ฅผ ์‚ฌ์šฉํ•œ ๊ฒฐ๊ณผ๋Š” ๋‹ค์Œ๊ณผ ๊ฐ™์Šต๋‹ˆ๋‹ค.


1. ์‹คํ–‰ ๊ฒฐ๊ณผ

const check = (event) => {
    console.log(event.target.textContent); 
}
const check = (event) => {
    console.log(event.target.innerText); 
}
const check = (event) => {
    console.log(event.target.innerHTML); 
}

textContent

text/plain์œผ๋กœ ํŒŒ์‹ฑํ•˜์—ฌ ๋ชจ๋“  ์š”์†Œ๋ฅผ ๋ฐ˜ํ™˜ํ•ฉ๋‹ˆ๋‹ค. <script>, <style> ์š”์†Œ๋ฅผ ํฌํ•จํ•ด CSS๋ฅผ ์‚ฌ์šฉํ•ด ์ˆจ๊ฒจ์ง„ ์š”์†Œ๋„ ํ•จ๊ป˜ ๋ฐ˜ํ™˜ํ•˜๋ฉฐ ์š”์†Œ์˜ ์›์‹œ ํ…์ŠคํŠธ๋ฅผ ์‚ฌ์šฉํ•˜๋ฏ€๋กœ ์„ฑ๋Šฅ์ด ์ข‹์Šต๋‹ˆ๋‹ค.

innerText

text/plain์œผ๋กœ ํŒŒ์‹ฑํ•˜์—ฌ ๋ Œ๋”๋ง ํ›„์˜ ์š”์†Œ๋ฅผ ๋ฐ˜ํ™˜ํ•ฉ๋‹ˆ๋‹ค. <script>, <style> ์š”์†Œ๋Š” ๋ฐ˜ํ™˜ํ•˜์ง€ ์•Š์œผ๋ฉฐ ์ˆจ๊ฒจ์ง„ ์š”์†Œ๋„ ๋ฐ˜ํ™˜ํ•˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค. ์ž์‹ ๋…ธ๋“œ๋ฅผ ๋ชจ๋‘ ์ œ๊ฑฐํ•˜๊ณ  ํ•˜๋‚˜์˜ ํ…์ŠคํŠธ๋กœ ๋ฐ˜ํ™˜๋˜๋ฉฐ ์„ฑ๋Šฅ์€ ๋ณดํ†ต์ž…๋‹ˆ๋‹ค.

innerHTML

text/html๋กœ ํŒŒ์‹ฑํ•˜์—ฌ ์š”์†Œ์˜ html, xml ์ „์ฒด๋ฅผ ๋ฐ˜ํ™˜ํ•ฉ๋‹ˆ๋‹ค. html์„ ๋‹ค๋ฃจ๋ฏ€๋กœ ๋ณด์•ˆ ์ด์Šˆ ์ค‘ ํ•˜๋‚˜์ธ XSS(Cross Site Scripting)์— ์ทจ์•ฝํ•ฉ๋‹ˆ๋‹ค. HTML5์—์„œ๋Š” innerHTML์— ์‚ฝ์ž…๋œ <script> ํƒœ๊ทธ๋Š” ์‹คํ–‰๋˜์ง€ ์•Š๋„๋ก ๋ณ€๊ฒฝ๋˜์—ˆ์ง€๋งŒ <img>๋“ฑ ๋‹ค๋ฅธ ํƒœ๊ทธ๋ฅผ ํ†ตํ•ด ์ ‘๊ทผํ•˜๋ฉด ์—ฌ์ „ํžˆ ์ทจ์•ฝ์ ์ด ๋‚จ์Šต๋‹ˆ๋‹ค. ๋”ฐ๋ผ์„œ innerHTML์€ ๋ณ„๋„๋กœ ๋ฌธ์ œ ๋ฐฉ์ง€๋ฅผ ์œ„ํ•œ ์„ค์ •์ด ์—†๋‹ค๋ฉด ์‚ฌ์šฉ์„ ๊ถŒ์žฅํ•˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค.



๊ตฌํ˜„๋„ ์ค‘์š”ํ•˜์ง€๋งŒ ์ƒํ™ฉ์— ๋งž๊ณ  ์ ์ ˆํ•œ ๋ฐฉ์‹์„ ํ†ตํ•ด ๊ตฌํ˜„ํ•œ ์‹œ์Šคํ…œ์— ๋ฌธ์ œ๊ฐ€ ์ƒ๊ธฐ์ง€ ์•Š๋„๋ก ์‚ฌ์ „์— ๋ฐฉ์ง€ํ•˜๋Š” ๊ฒƒ์ด ๋” ์ค‘์š”ํ•œ ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค. ์ ์ ˆํ•œ ๋ฐฉ์‹์„ ์„ ํƒํ•˜๋Š” ๊ฒƒ์€ ๊ฒฐ๊ตญ ๊ฐ ๊ธฐ๋Šฅ์˜ ์ดํ•ด๋ฅผ ํ†ตํ•ด์„œ์•ผ ๋น„๋กœ์†Œ ๊ฐ€๋Šฅํ•œ ๋ถ€๋ถ„์ด๋ฏ€๋กœ ํ•„์š”ํ•  ๋•Œ ์ •๋ฆฌ๋ฅผ ํ•ด๋‘๋ฉด ๋„์›€์ด ๋  ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค.

A Simple Explanation of Currying Functions(Javascript)

currying function’s usages, pros and cons

‘Currying’ has the same spelling as Curry that we love.

But ‘currying’ is derived from the name Haskell Brooks Curry who was known as a mathematician and a logician.

Currying is a technique that converting multiple arguments function into a single argument functions sequence.

Like this.

func(a, b, c) -> f(a)(b)(c)

Three arguments function is converted into three functions with single argument each.

f(a) returns value and (b) takes this value as a parameter. (c) also do the same thing. Get’s (b)‘s return value and return.

//non-curried
function plusFunc(a, b, c){
  console.log(a + b + c);
}

plusFunc(1, 2, 3);   // 6

//curried
function plusFunc(a){
    return function(b){
       return function(c){
          console.log(a + b + c);
       }
    }
}

plusFunc(1)(2)(4);  // 7

Then what are the differences between Curried and Non-curried?

non-curried : Function will be immediately executed even though parameters are not passed.
? Function definition : func(a, b, c)
? Function execution : func(a)
? Execution result : func(a, undefined, undefined)

curried : Execution will be suspended if parameters are not fully passed.
? Function definition : func(a, b, c)
? Function execution : func(a)
? Execution result : func(a) waits for b parameter.

So we can use currying as below.

function setAppell(appell){
    return function(name) {
       console.log(appell + name);   
    }
}

const setName = setAppell('Mr.');
setName('Right');  // Mr.Right
setAppell('Mr.')('Baker'); //Mr.Baker

//ES6 ํ™”์‚ดํ‘œ ํ•จ์ˆ˜
const setAppell = appell => name => console.log(appell + name);

const setName = setAppell('Miss.');
setName('Dior');  // Miss.Dior

If we use currying function, we can also pass event and value together.

const setNumber = (num) => (event) => {
     console.log(event.target.id+':'+num);
}

<div onClick="setNumber(2)(event)" id='myNum'>
  click
</div>

// myNum:2

What is Pros.

? Pros
Reusable
– Reduced amount of code
– Readability

And Cons.

? Cons
Deeply nested functions cause memory and speed issue. So Currying

Mathematical Explanations of Currying



Most of the functions can be implemented without using currying. but you can expect a good effect if you use currying to improve productivity through reusability or readability.

๋ฆฌ์•กํŠธ๊ฐ€ ํƒ€์ž…์Šคํฌ๋ฆฝํŠธ๋กœ ์ƒ์„ฑ์ด ์•ˆ๋  ๋•Œ(CRA + typescript not working)

create-react-app <project> –template typescript

๋ฆฌ์•กํŠธ+ํƒ€์ž…์Šคํฌ๋ฆฝํŠธ๋กœ ์ƒˆ ํ”„๋กœ์ ํŠธ๋ฅผ ์ƒ์„ฑํ•˜๊ณ ์ž create-react-app –template typescript๋ฅผ ์‹คํ–‰ํ•ด๋„ App.tsx๊ฐ€ ์•„๋‹Œ App.js๋กœ ์ƒ์„ฑ๋˜๋Š” ๊ฒฝ์šฐ๊ฐ€ ์žˆ์Šต๋‹ˆ๋‹ค.

cra-template-typescript ํŒจํ‚ค์ง€๊ฐ€ ์—†์–ด ๋ฐœ์ƒํ•˜๋Š” ๋ฌธ์ œ์ผ ๊ฐ€๋Šฅ์„ฑ์ด ์žˆ์œผ๋ฏ€๋กœ ํ•ด๋‹น ํŒจํ‚ค์ง€๋ฅผ ์„ค์น˜ํ•ด์ฃผ๊ณ  ์‹คํ–‰ํ•ด ๋ด…๋‹ˆ๋‹ค.

npm install cra-template-typescript -g

์„ค์น˜ ํ›„ ๋‹ค์‹œ create-react-app <projectName> –template typescript๋ฅผ ์‹คํ–‰ํ•œ ๊ฒฐ๊ณผ์ž…๋‹ˆ๋‹ค.


๋˜ ๋‹ค๋ฅธ ์›์ธ ์ค‘ ํ•˜๋‚˜๋Š” ์บ์‰ฌ์— ๋‚จ์•„์žˆ๋Š” ์ด์ „ ๋ฒ„์ „์œผ๋กœ ์„ค์น˜๊ฐ€ ๋˜์–ด ์ ์šฉ์ด ์•ˆ๋  ๊ฐ€๋Šฅ์„ฑ๋„ ์žˆ์œผ๋ฏ€๋กœ npm uninstall -g create-react-app๋ฅผ ํ†ตํ•ด ์‚ญ์ œ ํ›„ ์žฌ์„ค์น˜๋ฅผ ์ง„ํ–‰ํ•ด๋ณด๋Š” ๊ฒƒ๋„ ์ข‹์„ ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค.

CSS, ์•Œ๋ฉด ์‰ฌ์šด display ์†์„ฑ(inline, flex, …others)

inline, block, inline-block, flex, inline-flex, grid, inline-grid, none

display๋Š” ์š”์†Œ๋ฅผ ๋ณด์—ฌ์ฃผ๊ณ  ์ˆจ๊ธฐ๊ฑฐ๋‚˜ ์œ„์น˜๋ฅผ ์„ค์ •ํ•˜๊ธฐ ์œ„ํ•œ ์˜ต์…˜์œผ๋กœ, display๋งŒ ์ž˜ ์•Œ์•„๋„ ๋ ˆ์ด์•„์›ƒ์˜ ๋งŽ์€ ๋ถ€๋ถ„์„ ํ•ด๊ฒฐํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

์ด๋ฒˆ ํฌ์ŠคํŒ…์—์„œ display์˜ ์†์„ฑ์ธ inline, flex, inline-flex, block, inline-block, grid, inline-grid, none์˜ ๊ตฌํ˜„์„ ํ†ตํ•ด ๊ฐ๊ฐ์˜ ํ‘œ์‹œ ๋ฐฉ์‹์„ ์•Œ์•„๋ณด๋„๋ก ํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค.

์•Œ์•„๋ณด๊ธฐ ํŽธํ•˜๋„๋ก ๋ฐฐ๊ฒฝ์€ ๋ธ”๋ž™, ์š”์†Œ๋Š” ๊ฐ๊ฐ ๋ ˆ๋“œ, ์˜ค๋ Œ์ง€, ๊ทธ๋ฆฐ์œผ๋กœ ํ‘œํ˜„ํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค.

inline : inline์œผ๋กœ ํ‘œ์‹œ(width๋Š” ์š”์†Œ ํฌ๊ธฐ)
block : block์œผ๋กœ ํ‘œ์‹œ
inline-block : inline + block์œผ๋กœ ํ‘œ์‹œ
flex : ์ž์‹ ์š”์†Œ๋ฅผ ๋ชจ๋‘ inline-block์œผ๋กœ ์„ค์ •
inline-flex : inline + flex(์ „์ฒด width๋Š” ์ž์‹ width์˜ ํ•ฉ)
grid : flex์ฒ˜๋Ÿผ ํ•œ ๋ฐฉํ–ฅ์ด ์•„๋‹Œ ๊ฐ€๋กœ, ์„ธ๋กœ๋กœ ์„ค์ • ๊ฐ€๋Šฅํ•œ ๋ ˆ์ด์•„์›ƒ
inline-grid : inline + grid(์ „์ฒด width๋Š” ์ž์‹ width์˜ ํ•ฉ)
none : ํ‘œ์‹œํ•˜์ง€ ์•Š์Œ(๊ณต๊ฐ„์„ ์ฐจ์ง€ํ•˜์ง€ ์•Š์Œ)


์ค„๋ฐ”๊ฟˆ ์—†์ด ํƒœ๊ทธ๋ฅผ ํ‘œ์‹œํ•˜๋Š” ์š”์†Œ๋ฅผ inline ์š”์†Œ, ํƒœ๊ทธ๋งˆ๋‹ค ์ค„๋ฐ”๊ฟˆ์ด ๋˜๋Š” ์š”์†Œ๋ฅผ block ์š”์†Œ๋ผ๊ณ  ํ•ฉ๋‹ˆ๋‹ค.

๋Œ€ํ‘œ์ ์ธ inline ์š”์†Œ๋Š” <span>, <a> ๋“ฑ์ด ์žˆ์œผ๋ฉฐ, block ์š”์†Œ๋Š” <div>,<p>,<h1>,<h2> ๋“ฑ์ด ์žˆ์Šต๋‹ˆ๋‹ค.

๋จผ์ € ์•„๋ฌด ์†์„ฑ๋„ ์„ค์ •ํ•˜์ง€ ์•Š์€ div๋ฅผ ํ™•์ธํ•ด ๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค.

.setContainer{
  background-color:black;
}

.setOne{
  background-color: red;
}

.setTwo{
  background-color: orange;
  width:95%;
}

.setThree{
  background-color: green;
  width:90%;
}

<div class='setContainer'>
  <div class='setOne'>
    red
  </div>
  <div class='setTwo'>
    org
  </div>
  <div class='setThree'>
    grn
  </div>
</div>

div์˜ default ์„ค์ •์€ width 100%์ž…๋‹ˆ๋‹ค.

๊ธฐ๋ณธ ์„ค์ •์„ ํ™•์ธํ•˜๊ธฐ ์œ„ํ•ด setTwo์™€ setThree์— width๋ฅผ ์„ค์ •ํ•œ ๊ฒฐ๊ณผ์ž…๋‹ˆ๋‹ค.

๋จผ์ € display์˜ inline ์†์„ฑ์„ ํ™•์ธํ•ด๋ณด์ฃ .


1. inline

์œ„ ์†์„ฑ์€ ๋ง ๊ทธ๋Œ€๋กœ ์š”์†Œ๋ฅผ ์ผ๋ ฌ๋กœ ๋Š˜์–ด์„  ๋ฐฉ์‹์œผ๋กœ ํ‘œ์‹œํ•˜๋ฉฐ ์ค„๋ฐ”๊ฟˆ์„ ํ•˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค.

๊ฐ ์š”์†Œ๋งˆ๋‹ค ์„ค์ •ํ•˜๋ฉฐ width๋Š” ์ž๋™์œผ๋กœ ํฌ๊ธฐ์— ๋งž๊ฒŒ ๋ณ€ํ˜•๋ฉ๋‹ˆ๋‹ค.

.setContainer{
  background-color:black;
  display:inline;
}
.setOne{
  background-color: red;
  display:inline;
}
.setTwo{
  background-color: orange;
  display:inline;
}
.setThree{
  background-color: green;
  display:inline;
}

<div class='setContainer'>
  <div class='setOne'>
    red
  </div>
  <div class='setTwo'>
    org
  </div>
  <div class='setThree'>
    grn
  </div>
</div>

inline์€ ์œ„์™€ ๊ฐ™์ด ๋ฌธ์ž์—ด์ฒ˜๋Ÿผ ์ผ๋ ฌ๋กœ ๋Š˜์–ด์„  ์ƒํƒœ๋กœ ํ‘œ์‹œ๋ฉ๋‹ˆ๋‹ค.


2. block

block์€ inline ์š”์†Œ๋ฅผ block์œผ๋กœ ํ‘œ์‹œํ•ฉ๋‹ˆ๋‹ค.

block ์š”์†Œ div ๋Œ€์‹  inline ์š”์†Œ span์„ ์‚ฌ์šฉํ•˜๋ฉด ๋‹ค์Œ๊ณผ ๊ฐ™์€๋ฐ์š”.

์œ„์—์„œ div์— display:inline์„ ์„ค์ •ํ•œ ๊ฒƒ๊ณผ ๊ฐ™์€ ๋ชจ์–‘์ž…๋‹ˆ๋‹ค.

๊ทธ๋Ÿฌ๋ฏ€๋กœ span์— display:block์„ ์„ค์ •ํ•˜๋ฉด ๋ฐ˜๋Œ€๋กœ div๋ฅผ ์‚ฌ์šฉํ•œ ๊ฒƒ๊ณผ ๊ฐ™์€ ๊ฒฐ๊ณผ๊ฐ€ ๋‚˜์˜ค๋Š” ๊ฒƒ์„ ์•Œ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

.setContainer{
  background-color:black;
}
.setOne{
  background-color: red;
  display:block;
}
.setTwo{
  background-color: orange;
  display:block;
}
.setThree{
  background-color: green;
  display:block;
}

<div class='setContainer'>
  <span class='setOne'>red</span>
  <span class='setTwo'>org</span>
  <span class='setThree'>grn</span>
</div>

block ์†์„ฑ์€ inline ์š”์†Œ๋ฅผ block ์š”์†Œ์ฒ˜๋Ÿผ ํ‘œํ˜„ํ•˜๋Š” ๊ฒƒ์„ ์•Œ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.


3. inline-block

๊ทธ๋ ‡๋‹ค๋ฉด inline-block์€ ์–ธ์ œ ์‚ฌ์šฉํ• ๊นŒ์š”?

display:block์ด ํ•„์š”ํ•˜์ง€๋งŒ ํ‘œ์‹œ๋Š” inline์œผ๋กœ ํ‘œ์‹œ๋ฅผ ํ•˜๊ณ  ์‹ถ์€ ์ƒํ™ฉ์ž…๋‹ˆ๋‹ค.

๊ทธ๋Ÿฌ๋ฉด ๊ทธ๊ฒŒ ๊ทธ๋ƒฅ span์˜ default ์•„๋‹Œ๊ฐ€๋ผ๊ณ  ์ƒ๊ฐํ•  ์ˆ˜๋„ ์žˆ์ง€๋งŒ span์—๋Š” width, height ๋“ฑ ์†์„ฑ์ด ์ ์šฉ๋˜์ง€ ์•Š๊ธฐ ๋•Œ๋ฌธ์— block์œผ๋กœ ์„ค์ •์„ ํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.

์œ„์˜ ์ฝ”๋“œ์—์„œ ์ฒซ ๋ฒˆ์งธ ์š”์†Œ์— width:300px, height:200px๋ฅผ ์„ค์ •ํ•˜๋ฉด ๋‹ค์Œ ๊ทธ๋ฆผ๊ณผ ๊ฐ™์€ ๋ชจ์Šต์ด ๋ฉ๋‹ˆ๋‹ค.

์œ„ ์š”์†Œ๋ฅผ inline์œผ๋กœ ์„ค์ •ํ•˜๊ธฐ ์œ„ํ•ด inline-block๋ฅผ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

.setContainer{
  background-color:black;
}
.setOne{
  background-color: red;
  display:inline-block;
  width:300px;
  height:200px;
}
.setTwo{
  background-color: orange;
  display:inline-block;
}
.setThree{
  background-color: green;
  display:inline-block;
}

<div class='setContainer'>
  <span class='setOne'>red</span>
  <span class='setTwo'>org</span>
  <span class='setThree'>grn</span>
</div>

div๋ฅผ ์‚ฌ์šฉํ•ด ์œ„์™€ ๊ฐ™์ด ๋‚˜ํƒ€๋‚ด๋ ค๋ฉด ์–ด๋–ป๊ฒŒ ํ•ด์•ผ ํ• ๊นŒ์š”?

.setContainer{
  background-color:black;
}
.setOne{
  background-color: red;
  display:inline-block;
  width:300px;
  height:200px;
}
.setTwo{
  background-color: orange;
  display:inline;
}
.setThree{
  background-color: green;
display:inline;
}

<div class='setContainer'>
  <div class='setOne'>
    red
  </div>
  <div class='setTwo'>
    org
  </div>
  <div class='setThree'>
    grn
  </div>
</div>

์œ„์™€ ๊ฐ™์ด ์‚ฌ์šฉํ•˜๋ฉด ๋ฉ๋‹ˆ๋‹ค.

๋งŒ์•ฝ ์œ„์™€ ๊ฐ™์ด ์‚ฌ๊ฐํ˜• ์‚ฌ์ด ์‚ฌ์ด์— ๋นˆ๊ณต๊ฐ„์ด ๋“ค์–ด๊ฐ€๋Š” ๊ฒฝ์šฐ๊ฐ€ ์žˆ๋‹ค๋ฉด <div> ํƒœ๊ทธ ์‚ฌ์ด์˜ ๋„์›Œ์“ฐ๊ธฐ๋‚˜ ์ค„๋ฐ”๊ฟˆ์„ ํ™•์ธํ•ด๋ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.

๋ณด๊ธฐ์—๋Š” ์•ˆ์ข‹์ง€๋งŒ ๋‹ค์Œ๊ณผ ๊ฐ™์ด ํƒœ๊ทธ ์‚ฌ์ด๋ฅผ ๋ชจ๋‘ ๋ถ™์—ฌ์“ฐ๋ฉด ๊ณต๋ฐฑ์ด ๋ฐœ์ƒํ•˜๋Š” ๊ฒƒ์„ ์ œ๊ฑฐํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

<div class='setContainer'><div class='setOne'>red</div><div class='setTwo'>org</div><div class='setThree'>grn</div></div>

4. flex

flex๋Š” ์ƒˆ๋กœ์šด ์†์„ฑ ์ค‘ ํ•˜๋‚˜๋กœ ๋ถ€๋ชจ ์š”์†Œ์—์„œ๋งŒ ์„ค์ •์„ ํ•ฉ๋‹ˆ๋‹ค.

display:flex๋ฅผ ์„ค์ •ํ•˜๋ฉด ๋ชจ๋“  ์ž์‹ ์š”์†Œ์— display:inline-block์„ ์„ค์ •ํ•œ ๊ฒƒ๊ณผ ๊ฐ™์€ ํšจ๊ณผ๋ฅผ ์ค๋‹ˆ๋‹ค.

๋”ฐ๋ผ์„œ ๋ชจ๋“  ์ž์‹ ์š”์†Œ๋Š” display๋ฅผ ์„ค์ •ํ•  ํ•„์š” ์—†์ด width, height ๋“ฑ์˜ ์†์„ฑ์ด ์‚ฌ์šฉ ๊ฐ€๋Šฅํ•ฉ๋‹ˆ๋‹ค.

.setContainer{
  background-color:black;
  display:flex;  
}
.setOne{
  background-color: red;
}
.setTwo{
  background-color: orange;
  width:200px;
}
.setThree{
  background-color: green;
}

<div class='setContainer'>
  <div class='setOne'>
    red
  </div>
  <div class='setTwo'>
    org
  </div>
  <div class='setThree'>
    grn
  </div>
</div>

๊ฐœ๋ณ„ ์š”์†Œ์— ๋ชจ๋‘ display๋ฅผ ์„ค์ •ํ•  ํ•„์š” ์—†์ด ๋ถ€๋ชจ ์š”์†Œ์—์„œ๋งŒ ํŽธํ•˜๊ฒŒ ์„ค์ •์ด ๊ฐ€๋Šฅํ•ฉ๋‹ˆ๋‹ค.

๋งŒ์•ฝ ์ž์‹ ์š”์†Œ๋ฅผ ๊ฐ€์šด๋ฐ ์ •๋ ฌํ•˜๊ณ  ์‹ถ์œผ๋ฉด ๋ถ€๋ชจ ์š”์†Œ์—์„œ justify-content:center;๋ฅผ ์‚ฌ์šฉํ•˜๋ฉด ๋ฉ๋‹ˆ๋‹ค.


5. inline-flex

flex๋Š” ์ด๋ฏธ inline-block์˜ ๊ธฐ๋Šฅ์„ ๊ฐ–๊ณ  ์žˆ๋Š”๋ฐ ๊ทธ๋Ÿผ inline-flex์˜ ๊ธฐ๋Šฅ ๋ฌด์—‡์ผ๊นŒ์š”?

๋ฐ”๋กœ inline ํŠน์ง• ์ค‘ ํ•˜๋‚˜์ธ ์ž๋™ ํฌ๊ธฐ ์กฐ์ ˆ์ž…๋‹ˆ๋‹ค.

inline-flex๋Š” ์ž์‹ ์š”์†Œ๋ฅผ ํ•ฉ์นœ ํฌ๊ธฐ ๋งŒํผ๋งŒ ํฌ๊ธฐ๋ฅผ ์„ค์ •ํ•˜๋ฏ€๋กœ width๋Š” 100%๊ฐ€ ์•„๋‹Œ ์ž์‹ ํฌ๊ธฐ์˜ ํ•ฉ์ž…๋‹ˆ๋‹ค.

flex์˜ ๊ฒฐ๊ณผ์™€ ๋น„๊ตํ•ด๋ณด๋ฉด ์•Œ ์ˆ˜ ์žˆ๋“ฏ์ด ๋ถ€๋ชจ ์š”์†Œ๋ฅผ ์˜๋ฏธํ•˜๋Š” ๋ธ”๋ž™์ด ๊ณต๊ฐ„์„ ์ฐจ์ง€ํ•˜๊ณ  ์žˆ์ง€ ์•Š์Šต๋‹ˆ๋‹ค.


6. grid, inline-grid

์ด grid๋Š” ๋ฌด์—‡์ผ๊นŒ์š”?

๊ทธ๋ฆฌ๋“œ๋Š” flex์ฒ˜๋Ÿผ ๊ฐ€๋กœ๋‚˜ ์„ธ๋กœ ํ•œ ๋ฐฉํ–ฅ์œผ๋กœ๋งŒ ๋ ˆ์ด์•„์›ƒ์„ ์„ค์ •ํ•˜๋Š” ๊ฒƒ์ด ์•„๋‹ˆ๋ผ ๊ฐ€๋กœ, ์„ธ๋กœ ๋‘ ๋ฐฉํ–ฅ ๋ชจ๋‘ ์„ค์ •ํ•  ์ˆ˜ ์žˆ๋Š” ์†์„ฑ์ž…๋‹ˆ๋‹ค.

grid ์—ญ์‹œ ๋ถ€๋ชจ ์š”์†Œ์—์„œ ์„ค์ •์„ ํ•˜๋ฉฐ ์ž์‹ ์š”์†Œ๋ฅผ block์œผ๋กœ ํ‘œํ˜„ํ•ฉ๋‹ˆ๋‹ค.

๋‹ค์–‘ํ•œ ์†์„ฑ์„ ํ†ตํ•ด ๋ ˆ์ด์•„์›ƒ์„ ๊ตฌ์„ฑํ•˜๋Š”๋ฐ ํšจ๊ณผ์ ์ด์ง€๋งŒ ๋‚ด์šฉ์ด ๋งŽ์•„ ๋‹ค๋ฅธ ํฌ์ŠคํŒ…์„ ํ†ตํ•ด ์ข€ ๋” ์•Œ์•„๋ด์•ผ ํ•  ํ•„์š”์„ฑ์ด ์žˆ์„ ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค.

.setContainer{
  background-color:black;
  display:grid;  
  grid-template-columns: 100px 100px 100px;
}
.setOne{
  background-color: red;
}
.setTwo{
  background-color: orange;
}
.setThree{
  background-color: green;
}

<div class='setContainer'>
  <div class='setOne'>
    red
  </div>
  <div class='setTwo'>
    org
  </div>
  <div class='setThree'>
    grn
  </div>
</div>

inline-grid ์—ญ์‹œ inline-flex ์†์„ฑ๊ณผ ๋งˆ์ฐฌ๊ฐ€์ง€๋กœ width๋ฅผ ์ž์‹ ์š”์†Œ์— ๋งž๊ฒŒ ์กฐ์ ˆํ•˜๋Š” ๊ธฐ๋Šฅ์„ ํ•ฉ๋‹ˆ๋‹ค.


7. none

none์€ ํ•ด๋‹น ์š”์†Œ๋ฅผ ํ‘œ์‹œํ•˜์ง€ ์•Š์œผ๋ฉฐ ๊ณต๊ฐ„๋„ ์ฐจ์ง€ํ•˜์ง€ ์•Š๋Š” ๋ฐฉ์‹์ž…๋‹ˆ๋‹ค.

.setContainer{
  background-color:black;
}

.setOne{
  background-color: red;
  display:none;
}

.setTwo{
  background-color: orange;
}

.setThree{
  background-color: green;
}


<div class='setContainer'>
  <div class='setOne'>
    red
  </div>
  <div class='setTwo'>
    org
  </div>
  <div class='setThree'>
    grn
  </div>
</div>

์ด๋ ‡๊ฒŒ ์—†๋Š” ๋†ˆ ์ทจ๊ธ‰์„ ํ•ฉ๋‹ˆ๋‹ค.

์ด์™€ ๋ฐ˜๋Œ€๋˜๋Š” ์†์„ฑ์ด visibility๋กœ ์ด๋Š” ๊ณต๊ฐ„์€ ์ฐจ์ง€ํ•˜๋˜ ํ‘œ์‹œ๋งŒ ํ•˜์ง€ ์•Š๋Š” ์†์„ฑ์ž…๋‹ˆ๋‹ค.

visibility, display ์‚ฌ์šฉ ๊ด€๋ จ ํฌ์ŠคํŠธ

display:none์„ visibility:hidden์œผ๋กœ ๋ณ€๊ฒฝํ•œ ๊ฒฐ๊ณผ์ž…๋‹ˆ๋‹ค.

์žˆ๋Š”๋ฐ ์—†๋Š” ์ฒ™์„ ํ•ฉ๋‹ˆ๋‹ค.

๋ฌผ๋ก  visibility๋„ ๊ณต๊ฐ„๋งŒ ์ฐจ์ง€ํ•  ๋ฟ ํ•  ์ˆ˜ ์žˆ๋Š” ์ผ์€ ์—†์Šต๋‹ˆ๋‹ค.



CSS์˜ ๊ธฐ๋ณธ์ด์ง€๋งŒ ๋ชจ๋“  ๊ธฐ๋Šฅ์„ ๋‹ค ์ดํ•ดํ•˜๊ณ  ์‚ฌ์šฉํ•˜๊ธฐ๊นŒ์ง€๋Š” ์–ด๋Š ์ •๋„์˜ ์‹œ๊ฐ„๊ณผ ๊ฒฝํ—˜์ด ํ•„์š”ํ•œ ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค. ๋ฌด์ž‘์ • ์™ธ์šฐ๊ธฐ๋ณด๋‹ค๋Š” ์‚ฌ์šฉํ•˜๋ฉด์„œ ๋‹ต๋‹ตํ•จ์ด ์Œ“์˜€์„ ๋–„ ํ•œ๋ฒˆ์”ฉ ์†Œํ™”์ œ ๋Š๋‚Œ์œผ๋กœ ์„ค๋ช…์„ ์‚ผ์ผœ์ฃผ๋ฉด ์กฐ๊ธˆ ๋” ์™€๋‹ฟ๋Š” ์„ค๋ช…์ด ๋˜์ง€ ์•Š๋‚˜ ์‹ถ์Šต๋‹ˆ๋‹ค..๐Ÿง”

ํ…œํ”Œ๋ฆฟ ๋ฆฌํ„ฐ๋Ÿด(template literal)๊ณผ ์‰ฌ์šด ์‘์šฉ(feat.`)

`๋กœ ์‹œ์ž‘ํ•ด์„œ `๋กœ ๋๋‚˜๋Š” ํ…œํ”Œ๋ฆฟ ๋ฆฌํ„ฐ๋Ÿด

ํ…œํ”Œ๋ฆฟ ๋ฆฌํ„ฐ๋Ÿด(template literal)์€ ES6๋ถ€ํ„ฐ ๋„์ž…๋œ ๊ธฐ๋Šฅ์œผ๋กœ ๋ฌธ์ž์—ด ๋‹ค๋ฃจ๊ธฐ์— ํŠนํ™”๋œ ๊ธฐ๋Šฅ์ธ๋ฐ์š”.

` (backtick, grave accent)

ํ…œํ”Œ๋ฆฟ ๋ฆฌํ„ฐ๋Ÿด์€ ` ๊ธฐํ˜ธ๋กœ ์‹œ์ž‘ํ•ด ` ๊ธฐํ˜ธ๋กœ ๋๋‚˜๋ฉฐ, ๋ฌธ์ž์—ด๊ณผ ๋ณ€์ˆ˜๋ฅผ ํ•จ๊ป˜ ์ „๋‹ฌํ•˜๊ฑฐ๋‚˜ ํƒœ๊ทธ๋ฅผ ํŽธ๋ฆฌํ•˜๊ฒŒ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

๋˜ํ•œ ๋‹ค์Œ๊ณผ ๊ฐ™์€ ๋ฐฉ์‹๋„ ์‚ฌ์šฉ๋„ ๊ฐ€๋Šฅํ•œ๋ฐ์š”.

const printData = (text) => {
    console.log(text[0]); // 'Hello everyone!'
}

printData`Hello everyone!`;

ํ•จ์ˆ˜์— ํ…œํ”Œ๋ฆฟ ๋ฆฌํ„ฐ๋Ÿด์„ ์ „๋‹ฌํ•  ์ˆ˜๋„ ์žˆ์Šต๋‹ˆ๋‹ค.

์ด๋ฅผ ํƒœ๊ทธ๋“œ ํ…œํ”Œ๋ฆฟ(tagged template)์ด๋ผ๊ณ  ํ•˜๋Š”๋ฐ์š”.

ํ˜ธ์ถœ๋œ ํ•จ์ˆ˜๋Š” ํ…œํ”Œ๋ฆฟ ๋ฆฌํ„ฐ๋„ ๋‚ด ๋ฌธ์ž์—ด ์กฐ๊ฐ์ด๋‚˜ ํ‘œํ˜„์‹ ๋“ฑ์„ ๋งค๊ฐœ๋ณ€์ˆ˜๋กœ ๋ฐ›์Šต๋‹ˆ๋‹ค.

styled-components์—์„œ ์‚ฌ์šฉ๋˜๋Š” ๋ฐฉ์‹๋„ ํƒœ๊ทธ๋“œ ํ…œํ”Œ๋ฆฟ์ž…๋‹ˆ๋‹ค.


1. ํ…œํ”Œ๋ฆฟ ๋ฆฌํ„ฐ๋Ÿด(template literal)

ํ…œํ”Œ๋ฆฟ ๋ฆฌํ„ฐ๋Ÿด์€ ์‹œ์ž‘๊ณผ ๋์— ๋ฐ˜๋“œ์‹œ `(backtick)์„ ๋ถ™์—ฌ์•ผ ํ•˜๋ฉฐ, ‘(ํ™‘๋”ฐ์˜ดํ‘œ), “(์Œ๋”ฐ์˜ดํ‘œ)์™€ ๋ฐ˜๋“œ์‹œ ๊ตฌ๋ถ„ํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.

const name = 'clint Eastwood';
const age = '92';
const city = 'San Francisco';
const occupation = 'director';

// ํ‘œํ˜„์‹
console.log('His name is '+name+ '\n' + 'and '+age+'.');

// ํ…œํ”Œ๋ฆฟ ๋ฆฌํ„ฐ๋Ÿด
console.log(`He was born in ${city}
and he is a ${occupation}`);

ํ…œํ”Œ๋ฆฟ ๋ฆฌํ„ฐ๋Ÿด์—์„œ ${ }๋ฅผ ์‚ฌ์šฉํ•˜๋ฉด ๋ธ”๋ก ๋‚ด ๋ณ€์ˆ˜ ๋˜๋Š” ํ•จ์ˆ˜์— ์ ‘๊ทผ์ด ๊ฐ€๋Šฅํ•˜๋ฉฐ, \n ๋“ฑ ์ด์Šค์ผ€์ดํ”„๋ฅผ ์‚ฌ์šฉํ•˜์ง€ ์•Š๊ณ ๋„ ์ž…๋ ฅํ•œ๋Œ€๋กœ ์ถœ๋ ฅํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

ํ…œํ”Œ๋ฆฟ ๋ฆฌํ„ฐ๋Ÿด์€ ์‰ฝ๊ฒŒ ์‘์šฉ์ด ๊ฐ€๋Šฅํ•˜๋‹ˆ ํƒœ๊ทธ๋“œ ํ…œํ”Œ๋ฆฟ์— ๋Œ€ํ•ด ์•Œ์•„๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค.

2. ํƒœ๊ทธ๋“œ ํ…œํ”Œ๋ฆฟ(tagged template)

const TextBox = styled.div`
  display: inline-block;
  color: gray;
  margin: 0 auto;
`;

const StyledInput = styled.input`
    font-size: 1rem;
    border: none;
    border-bottom: 1px solid gray;
    outline: none;
    width: 100%;
`;

์œ„์™€ ๊ฐ™์ด styled-components์—์„œ ํƒœ๊ทธ๋“œ ํ…œํ”Œ๋ฆฟ์ด ๋ฐฅ ๋จน๋“ฏ์ด ์‚ฌ์šฉ๋ฉ๋‹ˆ๋‹ค.

ํ…œํ”Œ๋ฆฟ ๋ฆฌํ„ฐ๋Ÿด๋กœ ํ•จ์ˆ˜๋ฅผ ํ˜ธ์ถœํ•˜๋ฉด ์–ด๋–ป๊ฒŒ ์‚ฌ์šฉํ• ๊นŒ์š”?

ํ•จ์ˆ˜๋ฅผ ํ˜ธ์ถœํ•˜๋ฉด ๋งค๊ฐœ๋ณ€์ˆ˜๋กœ ๋ฌธ์ž์—ด๊ณผ ๋ณ€์ˆ˜๊ฐ€ ์ „๋‹ฌ๋ฉ๋‹ˆ๋‹ค.

const name = 'clint';
const age = '92';
const city = 'LA';

const showString = (text, ...args) => {
    console.log(text);
    console.log(args);
    console.log(text[2]);
    console.log(args[2]);
}

showString`He is ${name} and ${age}. From ${city}`;

์ „๋‹ฌ๋œ ๋งค๊ฐœ๋ณ€์ˆ˜๋Š” ํ…์ŠคํŠธ์™€ ${ }์— ๋„ฃ์€ ๋ณ€์ˆ˜์ด๋ฉฐ, ๊ฐ๊ฐ ํ™•์ธํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

ํ…์ŠคํŠธ์™€ ๋ณ€์ˆ˜์— ์ ‘๊ทผํ•˜๋ ค๋ฉด ์ธ๋ฑ์Šค๋ฅผ ์‚ฌ์šฉํ•˜๋ฉด ๋ฉ๋‹ˆ๋‹ค.

ํ…์ŠคํŠธ์˜ ๊ฒฝ์šฐ ${ }์ด ๋“ค์–ด๊ฐ„ ๋ถ€๋ถ„์—์„œ ๋Š์–ด์ฃผ๋ฏ€๋กœ ‘He is’, ‘ and ‘, ‘. From ‘, ”์ด๋ ‡๊ฒŒ ๋„ค ๋ถ€๋ถ„์œผ๋กœ ๋‚˜๋‰˜์–ด์ง€๋ฉฐ, ์ˆœ์„œ๋Œ€๋กœ 0, 1, 2, 3์˜ ์ธ๋ฑ์Šค๋ฅผ ๊ฐ–์Šต๋‹ˆ๋‹ค.

ํƒœ๊ทธ๋“œ ํ…œํ”Œ๋ฆฟ์„ ์‚ฌ์šฉํ•˜๋Š” ์ด์œ ๋Š” ๋ฌธ์ž์—ด์„ ์›ํ•˜๋Š” ํ˜•์‹์œผ๋กœ ์žฌ๊ฐ€๊ณตํ•˜์—ฌ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋Š” ์žฅ์ ์ด ์žˆ๊ธฐ ๋•Œ๋ฌธ์ž…๋‹ˆ๋‹ค.



styled-components๋ฅผ ๋ฌดํ„ฑ๋Œ€๊ณ  ์‚ฌ์šฉํ•˜๋Š” ๊ฒƒ๋ณด๋‹ค ๊ตฌ์กฐ๋ฅผ ์•Œ๊ณ  ์‚ฌ์šฉํ•˜๋ฉด ๋” ๋„์›€์ด ๋  ๊ฒƒ ๊ฐ™์•„ ํƒœ๊ทธ๋“œ ๋ฆฌํ„ฐ๋Ÿด์— ๋Œ€ํ•ด ์•Œ์•„๋ณด์•˜์Šต๋‹ˆ๋‹ค. ํ…œํ”Œ๋ฆฟ ๋ฆฌํ„ฐ๋Ÿด์€ ์ด์ œ ๋„ˆ๋ฌด ์œ ์šฉํ•˜๊ณ  ํŽธ๋ฆฌํ•œ ๊ธฐ๋Šฅ์ด๋ฏ€๋กœ ๊ผญ ์•Œ์•„๋‘์–ด์•ผ ํ•  ๊ธฐ๋Šฅ ์ค‘ ํ•˜๋‚˜์ธ ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค.

CSS transition, ์ž‘๋™ ์›๋ฆฌ ์ดํ•ดํ•˜๊ธฐ(์™œ ์ž‘๋™์„ ์•ˆํ• ๊นŒ?)

transition์˜ ์ž‘๋™์›๋ฆฌ์™€ transition ๋Œ€์ฒดํ•  ์ˆ˜ ์žˆ๋Š” ๋ฐฉ๋ฒ•

transition์€ ์• ๋‹ˆ๋ฉ”์ด์…˜ ํšจ๊ณผ๋ฅผ ์ฃผ๋Š” CSS์ž…๋‹ˆ๋‹ค.

transition ํ•˜๋‚˜๋งŒ์œผ๋กœ๋„ ํˆฌ๋ฐ•ํ•œ ๋Š๋‚Œ์„ ์ง€์šฐ๊ณ  ๋ถ€๋“œ๋Ÿฌ์šด ๋Š๋‚Œ์„ ์ค„ ์ˆ˜ ์žˆ๋Š”๋ฐ์š”.

๋ฉ”๋‰ด๊ฐ€ ๋ถ€๋“œ๋Ÿฝ๊ฒŒ ์—ด๋ฆฌ๊ณ  ๋‹ซํžˆ๊ฑฐ๋‚˜ ํ™”๋ฉด์— fade-in ํšจ๊ณผ ๋“ฑ์„ ์ค„ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

CSS์˜ ๋Œ€ํ‘œ์ ์ธ ์• ๋‹ˆ๋ฉ”์ด์…˜ ์ฒ˜๋ฆฌ๋Š” transition์™€ animation์ด ์žˆ๋Š”๋ฐ์š”.

transition์€ ๋ณ€๊ฒฝ์ด ๋ฐœ์ƒํ•˜๋Š” ์ˆœ๊ฐ„ ์ž‘๋™ํ•˜๊ณ , animation์€ transition๋ณด๋‹ค ๋” ์ž์œ ๋กญ๊ณ  ๋‹ค์–‘ํ•˜๊ฒŒ ์‚ฌ์šฉ์ด ๊ฐ€๋Šฅํ•œ ์นœ๊ตฌ์ž…๋‹ˆ๋‹ค.

๊ทธ๋Ÿผ transition์„ ์ž‘์„ฑํ•˜๋Š” ์ฝ”๋“œ๋ถ€ํ„ฐ ํ™•์ธํ•ด ๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค.

1. transition ์‚ฌ์šฉํ•˜๊ธฐ

.setBox{
  background-color:pink;
  width:200px;
  height:200px;
  transition:all 1000ms linear 500ms;
}

์œ„์™€ ๊ฐ™์€ ๋ฐฉ์‹์œผ๋กœ ์‚ฌ์šฉํ•˜๋ฉฐ, ํ•œ ์ค„ ํ‘œ๊ธฐ์˜ ์˜๋ฏธ๋Š” ๋‹ค์Œ๊ณผ ๊ฐ™์Šต๋‹ˆ๋‹ค.

transition: property duration timing delay;

property : color, background-color, border, position, all ๋“ฑ์˜ ์†์„ฑ

duration : ์™„๋ฃŒ๊นŒ์ง€ ๊ฑธ๋ฆฌ๋Š” ์‹œ๊ฐ„. ms(๋ฐ€๋ฆฌ์ดˆ) ๋˜๋Š” s(์ดˆ)๋กœ ์„ค์ •

timing : linear(๋™์ผ), ease(๋Š๋ฆผ->๋น ๋ฆ„->๋Š๋ฆผ), ease-in(๋Š๋ฆผ->๋น ๋ฆ„), ease-out(๋น ๋ฆ„->๋Š๋ฆผ)

delay : ๋”œ๋ ˆ์ด ์‹œ๊ฐ„(ms ๋˜๋Š” s๋กœ ์„ค์ •)

๋ฌผ๋ก  property๋‚˜ delay ๋Š” ์ƒ๋žต๋„ ๊ฐ€๋Šฅํ•ฉ๋‹ˆ๋‹ค.

์ด๋ฅผ ํ’€์–ด ์“ฐ๋ฉด ๋‹ค์Œ๊ณผ ๊ฐ™์ด ์ž‘์„ฑํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

transition-property : property
transition-duration : duration
transition-timing-function : timing
transition-delay: delay

transition์„ ์‚ฌ์šฉํ•ด ๋งˆ์šฐ์Šค๋ฅผ ์˜ฌ๋ฆฌ๋ฉด(hover) ๋ฐ•์Šค๊ฐ€ ๋ถ€๋“œ๋Ÿฝ๊ฒŒ ์ปค์กŒ๋‹ค๊ฐ€ ์ค„์–ด๋“œ๋Š” ์ฝ”๋“œ๋ฅผ ํ™•์ธํ•ด ๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค.

.setBox{
  background-color:pink;
  width:100px;
  height:50px;
  transition:all 1000ms linear 500ms;
}

.setBox:hover{
  background-color:gold;
  width:200px;
  height:100px;
  transition:all 300ms ease;
}

<div class='setBox'></div>

๋ฐ•์Šค๊ฐ€ ์ปค์งˆ ๋•Œ๋Š” .setBox:hover{}์˜ transition ์„ค์ •์— ๋”ฐ๋ผ 300ms, ์ค„์–ด๋“ค ๋•Œ๋Š” .setBox{}์˜ transition ์„ค์ •์— ๋”ฐ๋ผ 1000ms๋™์•ˆ ์›€์ง์ž…๋‹ˆ๋‹ค.

๊ทธ๋Ÿผ ์ด์ œ๋Š” ์š”์†Œ ์ˆจ๊ธฐ๊ธฐ&ํ‘œ์‹œํ•˜๊ธฐ ๊ธฐ๋Šฅ์„ ํ™•์ธํ•ด ๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค.

.setBox{
  background-color:gray;
  color:white;
  width:100px;
  height:50px;
  text-align:center;
  line-height:50px;
}
.showMenu{
  visibility:hidden;
  height:150px;
  width:100px;
  background-color:lightgray;
  opacity:0;
  color:black;
  border-radius:5px;
  transition:linear 500ms;
}
.setBox:hover .showMenu{
  visibility:visible;
  transition:linear 500ms;
  opacity:1;
}

<div class='setBox'>MENU
    <div class='showMenu'>
        <div class='menu'>
          ๋ฉ”๋‰ด A
        </div>
        <div class='menu'>
          ๋ฉ”๋‰ด B
        </div>
        <div class='menu'>
          ๋ฉ”๋‰ด C
        </div>
    </div>
</div>

์œ„ ์ฝ”๋“œ์˜ ์‹คํ–‰ ๊ฒฐ๊ณผ๋Š” ์•„๋ž˜์™€ ๊ฐ™์Šต๋‹ˆ๋‹ค.

๋งˆ์šฐ์Šค๋ฅผ ์˜ฌ๋ฆฌ๋ฉด ์ˆจ๊ฒจ๋‘” div๋ฅผ ํ‘œ์‹œํ•˜๊ฑฐ๋‚˜ ์ˆจ๊ธฐ๋ฉด์„œ transition์ด ์ž‘๋™ํ•˜๋Š” ๊ฒƒ์„ ๋ณผ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

์œ„ ์ฝ”๋“œ์—์„œ visibility๊ฐ€ ์•„๋‹Œ display๋ฅผ ์‚ฌ์šฉํ•˜๋ฉด ๊ฒฐ๊ณผ๋Š” ์–ด๋–จ๊นŒ์š”?

display๋ฅผ ์‚ฌ์šฉํ•˜๋ฉด transition์ด ์ž‘๋™ํ•˜์ง€ ์•Š๋Š” ๊ฒƒ์„ ๋ณผ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

์ด์œ ๋Š” ๋ฐ”๋กœ display์™€ visiblility์˜ ์ž‘๋™ ๋ฐฉ์‹์— ์ฐจ์ด๊ฐ€ ์žˆ์Šต๋‹ˆ๋‹ค.

transition์€ ์œ„์—์„œ ์ด์•ผ๊ธฐํ•œ ๊ฒƒ์ฒ˜๋Ÿผ ๋ณ€๊ฒฝ์ด ๋ฐœ์ƒํ•˜๋Š” ์ˆœ๊ฐ„ ์ž‘๋™ํ•ฉ๋‹ˆ๋‹ค.

์˜ˆ๋ฅผ ๋“ค์–ด A ๋ชจ์–‘์—์„œ B ๋ชจ์–‘์œผ๋กœ ๋ณ€๊ฒฝ๋  ๋•Œ ์ž‘๋™์„ ํ•˜๋Š”๋ฐ์š”.

visibility๋Š” ๊ณต๊ฐ„์€ ๊ทธ๋Œ€๋กœ ๋‘๊ณ  ์„ค์ •์— ๋”ฐ๋ผ ์š”์†Œ๋ฅผ ์ˆจ๊ธฐ๊ฑฐ๋‚˜ ๋‚˜ํƒ€๋‚ด๋ฏ€๋กœ A์—์„œ B๋กœ ๋ณ€๊ฒฝ์„ ์ ์šฉํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

๋‹ค์Œ ๊ทธ๋ฆผ๊ณผ ๊ฐ™์€ ๋Š๋‚Œ์ž…๋‹ˆ๋‹ค.


2. transition ์ž‘๋™ํ•˜์ง€ ์•Š๋Š” ์ด์œ 

๊ทธ๋ ‡๋‹ค๋ฉด display๊ฐ€ ์ž‘๋™ํ•˜์ง€ ์•Š๋Š” ์ด์œ ๋„ ์ถ”์ธกํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

display:none์€ ์š”์†Œ์˜ ํ‘œ์‹œ ๋ฟ๋งŒ ์•„๋‹ˆ๋ผ ํ‘œ์†Œ๊ฐ€ ์žˆ๋Š” ๊ณต๊ฐ„๋„ ๋น„์›Œ๋ฒ„๋ฆฌ๋Š” ์„ค์ •์ž…๋‹ˆ๋‹ค.

๋”ฐ๋ผ์„œ ‘A๋ชจ์–‘ -> B๋ชจ์–‘’์œผ๋กœ์˜ ๋ณ€ํ˜•์ด ์•„๋‹ˆ๋ผ ‘์—†์Œ -> B๋ชจ์–‘’ ์ด ๋˜๋ฏ€๋กœ transition์ด ์ž‘๋™ํ•˜์ง€ ์•Š๋Š” ๊ฒƒ์ž…๋‹ˆ๋‹ค.

๊ทธ๋Ÿฌ๋ฏ€๋กœ transition์€ ‘๋ชจ์–‘์˜ ๋ณ€ํ˜•‘๋งŒ ๊ธฐ์–ตํ•˜๋ฉด ๋ฉ๋‹ˆ๋‹ค.

๊ทธ๋ ‡๋‹ค๋ฉด ๊ฐ™์€ ํšจ๊ณผ๋ฅผ ๋‚ด๋Š” animation์€ ์–ด๋–ป๊ฒŒ ์‚ฌ์šฉํ• ๊นŒ์š”?

์ฝ”๋“œ๋งŒ ๋ด๋„ ์ดํ•ดํ•˜๊ธฐ ์‰ฌ์šด ๊ตฌ์กฐ์ด๋ฏ€๋กœ ์ฝ”๋“œ๋กœ ํ™•์ธํ•ด ๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค.

.setBox:hover .showMenu{
  visibility:visible;
  animation:setMotion 3s;
}
@keyframes setMotion{
  0%{
      opacity:0;
    }
  100%{
      opacity:1;
    }
}


CSS3๋Š” ์•„์ฃผ ๋‹ค์žฌ๋‹ค๋Šฅํ•œ ์นœ๊ตฌ๋ผ ๊ธฐ์กด์—๋Š” jquery๋ฅผ ์‚ฌ์šฉํ•ด ๋ณต์žกํ•˜๊ฒŒ ๊ตฌํ˜„ํ•  ์ˆ˜ ์žˆ๋˜ ์• ๋‹ˆ๋ฉ”์ด์…˜ ํšจ๊ณผ๋“ค์„ ์ด์ œ๋Š” ํ•œ ํ–‰์˜ ์ฝ”๋“œ๋งŒ์œผ๋กœ ํ•ด๊ฒฐํ•  ์ˆ˜ ์žˆ๊ฒŒ ๋˜๋ฉด์„œ CSS3๋Š” ์กฐ๊ธˆ๋งŒ ๋ฐฐ์›Œ ๋‘ฌ๋„ ์•„์ฃผ ์œ ์šฉํ•˜๊ฒŒ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋Š” ์นœ๊ตฌ๊ฐ€ ๋˜์—ˆ๋„ค์š”. CSS์— ์กฐ๊ธˆ ๋” ๊ด€์‹ฌ์„ ๊ฐ–๊ณ  ํฌ์ŠคํŒ…์„ ๋Š˜๋ ค ๊ฐ€์•ผ๊ฒ ์Šต๋‹ˆ๋‹ค.

does not have a commit checked out ์—๋Ÿฌ(Git)

git add ์‹œ ๋ฐœ์ƒํ•˜๋Š” ์—๋Ÿฌ๋ฅผ ํ•ด๊ฒฐํ•˜์ž

git add ๋ช…๋ น์–ด ์‹คํ–‰ ์‹œ does not have a commit checked out ์—๋Ÿฌ๊ฐ€ ๋ฐœ์ƒํ•˜๋Š” ๊ฒฝ์šฐ๊ฐ€ ์žˆ์Šต๋‹ˆ๋‹ค.

์ด๋Š” ๋ ˆํฌ์ง€ํ† ๋ฆฌ์— ์žˆ๋Š” ํด๋” ๋‚ด .git ํŒŒ์ผ์ด ์กด์žฌํ•˜๊ธฐ ๋•Œ๋ฌธ์ด๋ฉฐ ์ด ํŒŒ์ผ์„ ๋ชจ๋‘ ์ œ๊ฑฐํ•ด์ฃผ๋ฉด ๋ฌธ์ œ ์—†์ด git add ์‹คํ–‰์ด ๊ฐ€๋Šฅํ•ฉ๋‹ˆ๋‹ค.

ํŒŒ์ผ์ด ์ˆจ๊ฒจ์ ธ ์žˆ๊ธฐ ๋•Œ๋ฌธ์— ๊ฐ„๋‹จํ•˜๊ฒŒ ํด๋”๋‚˜ ํƒ์ƒ‰๊ธฐ๋ฅผ ์—ด๊ณ  ํ•ด๋‹น ํด๋” ๋‚ด ์ˆจ๊ฒจ์ ธ ์žˆ๋Š” .git ํŒŒ์ผ์„ ์ฐพ์•„ ๋ชจ๋‘ ์‚ญ์ œํ•ด์ฃผ๊ณ  ๋‹ค์‹œ git add๋ฅผ ์‹คํ–‰ํ•˜๋ฉด ๋ฉ๋‹ˆ๋‹ค.

์œ„์™€ ๊ฐ™์ด ํด๋”์—์„œ ‘์ˆจ๊ธด ํ•ญ๋ชฉ’์„ ์ฒดํฌํ•˜์—ฌ ํ‘œ์‹œํ•œ ๋‹ค์Œ .git์œผ๋กœ ๋œ ํด๋”๋ฅผ ์ œ๊ฑฐํ•ด์ฃผ๋ฉด ๋ฉ๋‹ˆ๋‹ค.

  1. git add๋ฅผ ํ•˜๋ ค๋Š” ํด๋”๋กœ ์ด๋™
  2. ์ˆจ๊ธด ํ•ญ๋ชฉ ํ•ด์ œ ํ›„ .git ํด๋” ์‚ญ์ œ
  3. git add <ํŒŒ์ผ> ์‹คํ–‰

๊ฐ„๋‹จํ•˜๊ฒŒ ์—๋Ÿฌ๊ฐ€ ํ•ด๊ฒฐ๋œ ๊ฒƒ์„ ๋ณผ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.



๊ธฐ๋ก์˜ ํž˜์„ ๋ฏฟ๊ณ  ๊ฐ„๋‹จํ•œ ๊ฒƒ์ด๋ผ๋„ ๊ธฐ๋กํ•˜๋Š” ์Šต๊ด€์„ ๊ธฐ๋ฅด๋„๋ก ๋…ธ๋ ฅ ์ค‘์ž…๋‹ˆ๋‹ค!

target์œผ๋กœ ๋ถ€๋ชจ ์š”์†Œ, ์ž์‹ ์š”์†Œ ์ ‘๊ทผํ•˜๊ธฐ(์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ,target)

event์™€ target์œผ๋กœ ๋ถ€๋ชจ ์š”์†Œ์™€ ์ž์‹ ์š”์†Œ์— ์ ‘๊ทผํ•˜๋Š” ๋ฐฉ๋ฒ•

์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ๋Š” ๋ณดํ†ต ์ด๋ฒคํŠธ์™€ target์„ ํ†ตํ•ด ์š”์†Œ์— ์ ‘๊ทผํ•ฉ๋‹ˆ๋‹ค.

๊ทธ๋ฆฌ๊ณ  <div>์™€ ๊ฐ™์€ ์š”์†Œ๋ฅผ ์ค‘์ฒฉํ•ด์„œ ์‚ฌ์šฉํ•˜๋‹ค ๋ณด๋ฉด ์ด๋ฒคํŠธ ๋ฐœ์ƒ ์‹œ ๋ถ€๋ชจ ์š”์†Œ ๋˜๋Š” ์ž์‹ ์š”์†Œ์— ์ ‘๊ทผ์ด ํ•„์š”ํ•œ ๊ฒฝ์šฐ๊ฐ€ ์žˆ์Šต๋‹ˆ๋‹ค.

์˜ˆ๋ฅผ ๋“ค๋ฉด ๋‹ค์Œ๊ณผ ๊ฐ™์ด id=2์ธ div ์š”์†Œ์˜ ์ด๋ฒคํŠธ๊ฐ€ ๋ฐœ์ƒํ–ˆ์„ ๋•Œ ๋ถ€๋ชจ div ์š”์†Œ id=1์— ์ ‘๊ทผํ•˜๊ณ  ์‹ถ์€ ๊ฒฝ์šฐ๊ฐ€ ์žˆ์Šต๋‹ˆ๋‹ค.

const check = (event) => {
    console.log(event.target.id);
}

<body>
  <div id=1>    
        <div id=2 onClick=(check(event))>click
            <div id=3></div>
            <div id=4></div>
        </div>
  </div>
</body>

๊ทธ๋ ‡๋‹ค๋ฉด ์–ด๋–ป๊ฒŒ ์ ‘๊ทผ์„ ํ•ด์•ผ ํ• ๊นŒ์š”?

1. ์ด๋ฒคํŠธ๋ฅผ ํ†ตํ•ด ๋ถ€๋ชจ ์š”์†Œ ์†์„ฑ ์ ‘๊ทผํ•˜๊ธฐ

ํ˜„์žฌ ์ด๋ฒคํŠธ๊ฐ€ ๋ฐœ์ƒํ•œ ์š”์†Œ๋ฅผ ๊ฐ์‹ธ๊ณ  ์žˆ๋Š” ๋ถ€๋ชจ ์š”์†Œ์— ์ ‘๊ทผํ•˜๊ธฐ ์œ„ํ•ด์„œ๋Š” target๊ณผ parentElement๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ์ ‘๊ทผํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

๋ถ€๋ชจ ์š”์†Œ์˜ id ์†์„ฑ์— ์ ‘๊ทผํ•˜๋Š” ์ฝ”๋“œ๋Š” ๋‹ค์Œ๊ณผ ๊ฐ™์Šต๋‹ˆ๋‹ค.

const check = (event) => {
    console.log(event.target.parentElement.id);    // 1
}

<body>
  <div id=1>    
        <div id=2 onClick=(check(event))>click
            <div id=3></div>
            <div id=4></div>
        </div>
  </div>
</body>

์‹คํ–‰ํ•ด๋ณด๋ฉด ์ฝ˜์†”์— 1์„ ํ”„๋ฆฐํŠธํ•ฉ๋‹ˆ๋‹ค.

๋งŒ์•ฝ id๊ฐ€ ์•„๋‹Œ ๋‹ค๋ฅธ ์†์„ฑ์— ์ ‘๊ทผํ•˜๊ณ  ์‹ถ์€ ๊ฒฝ์šฐ์—๋Š” id ๋Œ€์‹  ํ•ด๋‹น ์†์„ฑ๋ช…์„ ๊ทธ๋Œ€๋กœ ์‚ฌ์šฉํ•˜๋ฉด ๋ฉ๋‹ˆ๋‹ค.

๊ตฌ์กฐ๋ฅผ ํ™•์ธํ•˜๊ณ  ์‹ถ์€ ๊ฒฝ์šฐ์—๋Š” console.log(event.target.parentElement)์„ ์ž…๋ ฅํ•˜์—ฌ ํ™•์ธํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

console.log(event.target.parentElement)๊ฒฐ๊ณผ

ํ˜„์žฌ ์š”์†Œ๋ฅผ ๊ธฐ์ ์œผ๋กœ ์ ‘๊ทผ์„ ์ง„ํ–‰ํ•˜๋ฏ€๋กœ target์„ ์‚ฌ์šฉํ•˜๋ฉฐ, ์ด๋ฒคํŠธ๊ฐ€ ๊ธฐ์ ์ด ๋˜๋Š” ๊ฒฝ์šฐ currentTarget๋ฅผ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค.

๊ด€๋ จ ํฌ์ŠคํŠธ : target, currentTarget ์ฐจ์ด๊ฐ€ ๋ญ˜๊นŒ?


2. ์ด๋ฒคํŠธ๋ฅผ ํ†ตํ•ด ์ž์‹ ์š”์†Œ ์†์„ฑ ์ ‘๊ทผํ•˜๊ธฐ

์œ„ ์ฝ”๋“œ์—์„œ ๋ณด๋ฉด <div id=2>์˜ ์ž์‹ ์š”์†Œ๋Š” <div id=3>๊ณผ <div id=4>์ž…๋‹ˆ๋‹ค.

์ž์‹ ์š”์†Œ๋Š” target๊ณผ children์„ ํ†ตํ•ด ์ ‘๊ทผํ•˜๋Š”๋ฐ์š”.

๋ถ€๋ชจ ์š”์†Œ๋Š” ํ•˜๋‚˜๋ฐ–์— ์—†์ง€๋งŒ ์ž์‹ ์š”์†Œ๋Š” ์—ฌ๋Ÿฟ ์กด์žฌํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

๋”ฐ๋ผ์„œ ์ž์‹ ์š”์†Œ๋Š” ์ธ๋ฑ์Šค๋ฅผ ํ†ตํ•ด ์ ‘๊ทผํ•ด์•ผ ํ•˜๋ฉฐ, ๋ฆฌ์•กํŠธ ์ฝ”๋“œ๋ฅผ ํ†ตํ•ด ์ž์‹ ์š”์†Œ์˜ ๊ตฌ์กฐ๋ฅผ ์‚ดํŽด๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค.

const accessChildren = () => {

const check = (e) => {
    console.log(e.target.children)
}

    return (
        <div id={1}>    
            <div id={2} onClick={check}>click
                <div id={3}>I'm a first child</div>
                <div id={4}></div>
            </div>
        </div>
    )
}

export default accessChildren;

์ฝ˜์†”์— ์ฐํžˆ๋Š” children์˜ ๊ตฌ์กฐ๋Š” ๋‹ค์Œ๊ณผ ๊ฐ™์ด ๋‘ ๊ฐœ์˜ object๋ฅผ ๊ฐ–์Šต๋‹ˆ๋‹ค.

๋”ฐ๋ผ์„œ ์ฒซ ๋ฒˆ์งธ ์ž์‹ ์š”์†Œ์˜ id์— ์ ‘๊ทผํ•˜๊ธฐ ์œ„ํ•ด์„œ๋Š” ๋‹ค์Œ๊ณผ ๊ฐ™์ด ์‚ฌ์šฉํ•˜๋ฉด ๋ฉ๋‹ˆ๋‹ค.

const check = (e) => {
    console.log(typeof(e.target.children[0].id)) // 3
}

๊ทธ๋ ‡๋‹ค๋ฉด ์ฒซ ๋ฒˆ์งธ ์ž์‹ ์š”์†Œ์˜ ํ…์ŠคํŠธ์ธ I’m a first child๋Š” ์–ด๋–ป๊ฒŒ ์ ‘๊ทผํ• ๊นŒ์š”?

๊ฐ„๋‹จํ•˜๊ฒŒ ์œ„ children ๊ตฌ์กฐ๋ฅผ ์—ด์–ด์„œ ์‚ดํŽด๋ณด๋ฉด ๋‹ต์ด ๋‚˜์˜ต๋‹ˆ๋‹ค.

textContent๋ฅผ ์‚ฌ์šฉํ•ด์„œ ์ ‘๊ทผํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. (innerHTML์€ XSS์— ์ทจ์•ฝ)

const check = (e) => {
    console.log(e.target.children[0].textContent) //I'm a first child
}


ํŠน์ • ์š”์†Œ๊ฐ€ ์†ํ•œ ์†์„ฑ ์ „์ฒด(์˜ˆ๋ฅผ ๋“ค๋ฉด e.target)๋ฅผ ์ฝ˜์†”์— ์ถœ๋ ฅํ•˜๋ฉด ๋‹ค์–‘ํ•œ ํ•˜์œ„ ์†์„ฑ์„ ํ™•์ธํ•  ์ˆ˜ ์žˆ์œผ๋ฏ€๋กœ ์›ํ•˜๋Š” ์†์„ฑ์„ ์ฐพ๊ฑฐ๋‚˜ ์—๋Ÿฌ๋ฅผ ํ•ด๊ฒฐํ•  ๋•Œ ์œ ์šฉํ•˜๊ฒŒ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

๋น…์˜ค ํ‘œ๊ธฐ๋ฒ•(Big O notation)์„ ์•Œ์•„๋ณด์ž

์•Œ๊ณ ๋ฆฌ์ฆ˜์˜ ํšจ์œจ์„ฑ์„ ๋‚˜ํƒ€๋‚ด๋Š” ๋น…์˜ค ํ‘œ๊ธฐ๋ฒ•

๋น…์˜ค(Big O) ํ‘œ๊ธฐ๋ฒ•์€ ์ ๊ทผ์  ํ‘œ๊ธฐ๋ฒ•(Asymptotic Notation)์˜ ํ•˜๋‚˜๋กœ Landau symbol์ด๋ผ๊ณ  ๋ถ€๋ฅด๊ธฐ๋„ ํ•˜๋ฉฐ, ์•Œ๊ณ ๋ฆฌ์ฆ˜์˜ ํšจ์œจ์„ฑ(์‹œ๊ฐ„ ๋ณต์žก๋„)๋ฅผ ๋‚˜ํƒ€๋‚ผ ๋•Œ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค.

๊ทธ๋ ‡๋‹ค๋ฉด ์ ๊ทผ์  ํ‘œ๊ธฐ๋ฒ•์ด๋ž€ ๋ฌด์—‡์ผ๊นŒ?

์ ๊ทผ์  ํ‘œ๊ธฐ๋ฒ•์€ ์ค‘์š”ํ•˜์ง€ ์•Š์€ ์ƒ์ˆ˜์™€ ๊ณ„์ˆ˜๋ฅผ ์ œ๊ฑฐํ•˜์—ฌ ์•Œ๊ณ ๋ฆฌ์ฆ˜์˜ ๋ณต์žก๋„๋ฅผ ๋‹จ์ˆœํ™”ํ•˜์—ฌ ๋‚˜ํƒ€๋‚ผ ๋•Œ ์‚ฌ์šฉํ•˜๋Š” ํ‘œ๊ธฐ๋ฒ•์ž…๋‹ˆ๋‹ค.

์ ๊ทผ์  ํ‘œ๊ธฐ๋ฒ•์€ ๋น… ์„ธํƒ€(Big-ฮธ), ๋น… ์˜ค(Big-O), ๋น… ์˜ค๋ฉ”๊ฐ€(Big-ฮฉ)๊ฐ€ ์žˆ์œผ๋ฉฐ ๋Œ€๋žต์ ์ธ ์˜๋ฏธ๋Š” ๋‹ค์Œ๊ณผ ๊ฐ™์Šต๋‹ˆ๋‹ค.

๋น… ์˜ค(Big-O)์ ๊ทผ์  ์ƒํ•œ์— ๋Œ€ํ•œ ํ‘œ๊ธฐex) O(nยฒ)
๋น… ์„ธํƒ€(Big-ฮธ)์ƒํ•œ๊ณผ ํ•˜ํ•œ์˜ ํ‰๊ท ์— ๋Œ€ํ•œ ํ‘œ๊ธฐex) ฮธ(nยฒ)
๋น… ์˜ค๋ฉ”๊ฐ€(Big-ฮฉ)์ ๊ทผ์  ํ•˜ํ•œ์— ๋Œ€ํ•œ ํ‘œ๊ธฐex) ฮฉ(nยฒ)

๋น… ์„ธํƒ€์™€ ๋น… ์˜ค๋ฉ”๊ฐ€๋Š” ์›ํ•˜๋Š” ํšจ์œจ์„ฑ์„ ์ •ํ™•ํ•˜๊ฒŒ ๋‚˜ํƒ€๋‚ด์ง€ ๋ชปํ•˜๋Š” ๊ด€๊ณ„๋กœ ๋น… ์˜ค ํ‘œ๊ธฐ๋ฒ•์ด ์ฃผ๋กœ ์‚ฌ์šฉ๋ฉ๋‹ˆ๋‹ค.

์•Œ๊ณ ๋ฆฌ์ฆ˜์˜ ๋Œ€๋žต์ ์ธ ์‹คํ–‰ ์‹œ๊ฐ„๋งŒ ์•Œ๋ฉด ๋˜๋ฏ€๋กœ ๋น… ์˜ค ํ‘œ๊ธฐ๋ฒ•์€ ์ฐจ์ˆ˜๊ฐ€ ๊ฐ€์žฅ ๋†’์€ ํ•ญ๋งŒ ์‚ฌ์šฉํ•ด ์ˆ˜ํ–‰ ์‹œ๊ฐ„์˜ ์ƒํ•œ(์ตœ์•…์˜ ๊ฒฝ์šฐ)์„ ๋‚˜ํƒ€๋ƒ…๋‹ˆ๋‹ค.

์˜ˆ๋ฅผ ๋“ค์–ด f(n)=3nยฒ+2n+1์ผ ๋•Œ, ๋น… ์˜ค ํ‘œ๊ธฐ๋ฒ•์„ ์‚ฌ์šฉํ•˜๋ฉด O(nยฒ)๋กœ ๋‚˜ํƒ€๋‚ผ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

์ž…๋ ฅ๊ฐ’์ด ์ž‘์„ ๋•Œ๋Š” ๋ฌธ์ œ๊ฐ€ ์—†์ง€๋งŒ ์ž…๋ ฅ๊ฐ’์ด ๋ฌดํ•œ๋Œ€์— ๊ฐ€๊นŒ์›Œ์ง€๋Š” ๊ฒฝ์šฐ์—๋Š” ๊ธฐํ•˜ ๊ธ‰์ˆ˜์ ์œผ๋กœ ๋ณต์žก๋„๊ฐ€ ์ฆ๊ฐ€ํ•˜๋ฉฐ ์ฃผ์š” ์ฆ๊ฐ€์œจ์€ ๋‹ค์Œ๊ณผ ๊ฐ™์Šต๋‹ˆ๋‹ค.

์‹œ๊ฐ„ ๋ณต์žก๋„n์ด 2๋ฐฐ๊ฐ€ ๋  ๊ฒฝ์šฐ
O(1)๋ณ€ํ•จ X
O(log n)์•ฝ๊ฐ„ ์ฆ๊ฐ€
O(n)2๋ฐฐ ์ฆ๊ฐ€
O(n log n)2๋ฐฐ๋ณด๋‹ค ์•ฝ๊ฐ„ ์ฆ๊ฐ€
O(n2)4๋ฐฐ ์ฆ๊ฐ€
O(n3)8๋ฐฐ ์ฆ๊ฐ€
O(nk)2k๋ฐฐ ์ฆ๊ฐ€
O(kn)kn๋ฐฐ ์ฆ๊ฐ€
O(n!)nn๋ฐฐ ์ฆ๊ฐ€

์ฆ๊ฐ€์œจ์„ ๊ทธ๋ž˜ํ”„๋กœ ๋ณด๋ฉด ๋‹ค์Œ๊ณผ ๊ฐ™์Šต๋‹ˆ๋‹ค.

๊ทธ๋ž˜ํ”„ ๊ธฐ์šธ๊ธฐ๊ฐ€ ์™„๋งŒํ• ์ˆ˜๋ก ํšจ์œจ์ด ์ข‹์€ ๊ฒƒ์„ ๋‚˜ํƒ€๋‚ด๋ฉฐ ๊ธฐ์šธ๊ธฐ๊ฐ€ ๊ฐ€ํŒŒ๋ฅผ์ˆ˜๋ก ํšจ์œจ์„ฑ์ด ๋‚˜์œ ๊ฒƒ์„ ์˜๋ฏธํ•ฉ๋‹ˆ๋‹ค.

์ถœ์ฒ˜ : https://en.wikipedia.org/wiki/Big_O_notation

์œ„ ๊ทธ๋ž˜ํ”„๋ฅผ ํ†ตํ•ด ์ƒ์ˆ˜->๋กœ๊ทธ->์„ ํ˜•->๋‹คํ•ญ->์ง€์ˆ˜->ํŒฉํ† ๋ฆฌ์–ผ์˜ ์ˆœ์œผ๋กœ ํšจ์œจ์ด ๋–จ์–ด์ง€๊ณ  ์žˆ๋Š” ๊ฒƒ์„ ์•Œ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

ใ‚ธใƒฃใƒใ‚นใ‚ฏใƒชใƒ—ใƒˆใ€ๆ–‡ๅญ—ๅˆ—ๆ“ไฝœ(JAVASCRIPT & STRING)

Javascriptๆ–‡ๅญ—ๅˆ—ใฎใƒกใ‚ฝใƒƒใƒ‰ : slice(), substring(), includes(), startsWith(), trim(), replace()…….

ใƒ•ใƒญใƒณใƒˆใ‚จใƒณใƒ‰(React, Vue, Angular)ใ‚‚ใƒใƒƒใ‚ฏใ‚จใƒณใƒ‰(Nodejs)ใ‚‚ใ‚ธใƒฃใƒใ‚นใ‚ฏใƒชใƒ—ใƒˆ(Javascript)ใŒไฝฟใ‚ใ‚Œใ‚‹ๆ™‚ไปฃใซใชใฃใฆใ€ใ ใ‚“ใ ใ‚“ใ‚ธใƒฃใƒใ‚นใ‚ฏใƒชใƒ—ใƒˆใฎๆ–‡ๆณ•ใŒ้‡่ฆใจใชใ‚Šใพใ™ใญใ€‚

ใใฎไธญใ€ๆ–‡ๅญ—ๅˆ—(String)้–ข้€ฃใฎใƒกใ‚ฝใƒƒใƒ‰ใฏใ‚ˆใไฝฟใ†ใฎใซใ€ใ‚ใพใ‚Š่ฆšใˆใฆใฏใ„ใชใ„ใ‚„ใคใงใ™ใญใ€‚๐Ÿ˜‚

ๆ–‡ๅญ—ๅˆ—้–ข้€ฃใฎใƒกใ‚ฝใƒƒใƒ‰ใฏไธ€ๅบฆ่ฆšใˆใฆใŠใใจ่‡ชๅ‹•ใซ่ฆšใˆใ‚‰ใ‚Œใ‚‹ใใ‚‰ใ„ไฝฟใ†้ ปๅบฆใŒ้ซ˜ใ„ใฎใงๆœ€ๅˆใ ใ‘้ ‘ๅผตใ‚Œใฐใงใ™ใญ๏ผ

ใงใฏใ€้ ป็นใซไฝฟใ†ใƒกใ‚ฝใƒƒใƒ‰ใฎไธญslice(), substring(), includes(), startsWith(), trim(), replace(), indexOf(), test()ใ‚’ใ”็ดนไป‹ใ—ใพใ™ใ€‚


sliceใƒกใ‚ฝใƒƒใƒ‰ใฏใ‚คใƒณใƒ‡ใƒƒใ‚ฏใ‚นใ‚’ใƒ‘ใƒฉใƒกใƒผใ‚ฟใงๆธกใ—ใ€ๅฟ…่ฆใชๆ–‡ๅญ—ๅˆ—ใ‚’ๆŠฝๅ‡บใ—ใพใ™ใ€‚

ใ‚นใ‚ฟใƒผใƒˆใ‚คใƒณใƒ‡ใƒƒใ‚ฏใ‚น(start index)ใจ็ต‚ไบ†ใ‚คใƒณใƒ‡ใƒƒใ‚ฏใ‚น(end indexใ€็œ็•ฅๅฏ)ใ‚’ๆธกใ—ใ€็ต‚ไบ†ใ‚คใƒณใƒ‡ใƒƒใ‚ฏใ‚นใ‚’็œ็•ฅใ™ใ‚‹ๅ ดๅˆใฏๆ–‡ๅญ—ๅˆ—ใฎๆœ€ๅพŒใพใงใซใชใ‚Šใพใ™ใ€‚

ใƒ‘ใƒฉใƒกใƒผใ‚ฟใŒ๏ผใฎๅ ดๅˆใฏ้ ญใ‹ใ‚‰ไธ€็•ช็›ฎใ€-1ใฏ้€†ใงๅพŒใ‚ใ‹ใ‚‰ไธ€็•ช็›ฎใฎๆ„ๅ‘ณใซใชใ‚Šใพใ™ใ€‚

const myWord = 'primavera';

myWord.slice(0,5);   // 'prima'
myWord.slice(-4);    // 'vera'
myWord.slice(3);     // 'mavera'

myWord.slice(3,1);    // '' -> slice()ใฏใ‚นใ‚ฟใƒผใƒˆใŒ็ต‚ไบ†ใ‚ˆใ‚Šๅคงใใ„ใจ็ฉบใ‚’่ฟ”ใ™

substringใƒกใ‚ฝใƒƒใƒ‰ใ‚‚sliceใจๅŒใ˜ใใ‚คใƒณใƒ‡ใƒƒใ‚ฏใ‚นใ‚’ๆธกใ—ใ€ๆ–‡ๅญ—ๅˆ—ใ‚’ๆŠฝๅ‡บใ—ใพใ™ใ€‚

ๅŸบๆœฌ็š„ใชๆ“ไฝœใฏๅŒๆง˜ใงใ™ใŒsubstringใฏใ‚นใ‚ฟใƒผใƒˆใŒ็ต‚ไบ†ใ‚ˆใ‚Šๅคงใใ„ใฎๅ ดๅˆ่‡ชๅ‹•ใซไฝ็ฝฎใ‚’ไบคๆ›ใ—ใฆใƒกใ‚ฝใƒƒใƒ‰ใ‚’ๅฎŸๆ–ฝใ—ใพใ™ใ€‚

ใพใŸใ€substringใซ่ฒ ๆ•ฐใ‚’ๅ…ฅใ‚Œใ‚‹ใจ๏ผใจ่ช่ญ˜ใ—ใพใ™ใ€‚

ไพ‹ใˆใฐ(3, -1)ใ‚’ๆธกใ™ใจ(3, 0)ใจใ—ใฆ่ช่ญ˜ใ—ใพใ™ใ€‚ใใ‚Œใซ(3, 0)ใฏใ‚นใ‚ฟใƒผใƒˆใŒๅคงใใ„ใฎใง่‡ชๅ‹•ไบคๆ›ใ—ใ€(0, 3)ใ‚’ๅฎŸๆ–ฝใ—ใพใ™ใ€‚

ใƒกใ‚ฝใƒƒใƒ‰ๅใŒไผผใŸใ‚ˆใ†ใชsubstrใฏโ€™ไฝ็ฝฎโ€™ใจโ€™ๆ–‡ๅญ—ๆ•ฐ’ใ‚’ใƒ‘ใƒฉใƒกใƒผใ‚ฟใซๆธกใ™ใƒกใ‚ฝใƒƒใƒ‰ใงใ™ใ€‚

const myWord = 'invierno';

myWord.substring(3);     // 'ierno'
myWord.substring(1,3);   // 'nv'

myWord.substring(3,1);   // 'nv' -> ่‡ชๅ‹•ใซใ‚นใ‚ฟใƒผใƒˆใจ็ต‚ไบ†ไฝ็ฝฎไบคๆ›

myWord.substring(3,-1);  // 'inv' -> ่ฒ ๆ•ฐใฏ0, ่‡ชๅ‹•ไฝ็ฝฎไบคๆ›

myWord.substring(-4);    // 'invierno' -> ่ฒ ๆ•ฐใฏ0, ใ‚นใ‚ฟใƒผใƒˆ(0)ใ‹ใ‚‰ๆœ€ๅพŒใพใง

myWord.substr(1,3);      // 'nvi' -> ใ‚นใ‚ฟใƒผใƒˆ1ใ‹ใ‚‰ไธ‰ใค

includesใฏๆ–‡ๅญ—ๅˆ—ใฎไธญใ€ๆŒ‡ๅฎšใ—ใŸๆ–‡ๅญ—ๅˆ—ใŒๅซใพใ‚Œใฆใ„ใ‚‹ใ‹ใ‚’ใƒใ‚งใƒƒใ‚ฏใ—ใพใ™ใ€‚

ใƒ‘ใƒฉใƒกใƒผใ‚ฟใฏๆ–‡ๅญ—ๅˆ—(ๅฟ…้ ˆ)ใจใ‚คใƒณใƒ‡ใƒƒใ‚ฏใ‚น(็œ็•ฅๅฏ)ใ‚’ๆธกใ—ใ€่ฟ”ใ™ใฎใฏtrueๆˆ–ใฏfalseใงใ™ใ€‚

ใ“ใฎใƒกใ‚ฝใƒƒใƒ‰ใฏๆŒ‡ๅฎšๆ–‡ๅญ—ใฏใ‚‚ใกใ‚ใ‚“ใ€้…ๅˆ—ใฎไธญใง็ฉบใฎๅ€คใ‚’็ขบ่ชใ™ใ‚‹ใŸใ‚ใซใฏไฝฟใˆใพใ™ใ€‚

const myWord = 'alegria';

myWord.includes('le');       // true
myWord.includes('i');        // true
myWord.includes('rio');      // false

const myArray = ['dream','','king'];
myArray.includes('');       // true   -> myArray[1]ใŒ็ฉบใชใฎใงtrue
myArray.includes('dream');  // true   -> myArray[0]ใจไธ€่‡ด
myArray.includes('drea');   // false  -> ่ฆ็ด ใฏๅฎŒๅ…จไธ€่‡ดใ™ใ‚‹ๅ ดๅˆใฎใฟtrue

startsWithใƒกใ‚ฝใƒƒใƒ‰ใ‚‚ๆ–‡ๅญ—ๅˆ—ใŒๅซใพใ‚Œใฆใ„ใ‚‹ใ‹ใ‚’ใƒใ‚งใƒƒใ‚ฏใ—ใพใ™ใ€‚

ๆ–‡ๅญ—ๅˆ—ใฎใฟๆธกใ™ใจ0ใ‚คใƒณใƒ‡ใƒƒใ‚ฏใ‚นใ‹ใ‚‰ๅง‹ใพใ‚‹ๆŒ‡ๅฎšๆ–‡ๅญ—ใฎๅญ˜ๅœจใ‚’็ขบ่ชใ—ใ€BOOLEANใ‚’่ฟ”ใ—ใพใ™ใ€‚

endsWithใฏๆŒ‡ๅฎšๆ–‡ๅญ—ใง็ต‚ใ‚ใ‚‹ใ“ใจใ‚’ใƒใ‚งใƒƒใ‚ฏใ—ใพใ™ใ€‚

const mySentence = 'cafe con leche';

mySentence.startsWith('cafe');     // true
mySentence.startsWith('fe');       // false
mySentence.startsWith('fe',2);     // true

mySentence.endsWith('eche');      // true

trimใฏๆ–‡ๅญ—ๅˆ—ไธกๆ–ญใฎ็ฉบ็™ฝใ‚’้™คใใƒกใ‚ฝใƒƒใƒ‰ใงใ™ใ€‚

ๆ–‡ๅญ—ๅˆ—ๅค‰ๆ›ใฎ้Ž็จ‹ใงๅ…ฅใ‚‰ใ‚ŒใŸ็ฉบ็™ฝใพใŸใฏใ‚ฟใ‚คใƒ—ใƒŸใ‚นใงๅ…ฅใฃใŸๆ–‡ๅญ—ๅˆ—ใฏๆ–‡ๅญ—ๆฏ”่ผƒใฎๆ™‚falseใ‚’่ฟ”ใ—ใ€ใ‚จใƒฉใƒผใซใชใ‚ŠใŒใกใงใ™ใ€‚

ใชใฎใงtrimใง็ฉบ็™ฝใ‚’ไบ‹ๅ‰ใซ้™คใใ€ใ‚จใƒฉใƒผใ‚’ไบˆ้˜ฒใ™ใ‚‹ใ“ใจใŒใงใใพใ™ใ€‚

ๆ–‡ๅญ—ๅˆ—ไธกๆ–ญใฎ็ฉบ็™ฝใ€ใ‚ฟใƒƒใƒ—ใ€ๆ”น่กŒ(/n)ๆ–‡ๅญ—ใ‚’้™คใใ“ใจใŒใงใใพใ™ใŒใ€ไธกๆ–ญใงใฏใชใๆ–‡ๅญ—ๅˆ—ไธญใซๅ…ฅใฃใฆใ„ใ‚‹ใฎใฏไฝœๅ‹•ใ—ใพใ›ใ‚“ใ€‚

const mySentence = '  la casa de papel   ';

mySentence.trim();        // 'la casa de papel'

const mySentence = ' el amor \n';

mySentence.trim();       // 'el amor'

replaceใฏๆ–‡ๅญ—ๅˆ—ใ‹ใ‚‰ๆŒ‡ๅฎšใ—ใŸๆ–‡ๅญ—ใ‚’ๆŽขใ—ใฆๅค‰ๆ›ๆ–‡ๅญ—ใซๅค‰ๆ›ใ—ใพใ™ใ€‚

ๆ–‡ๅญ—ๅˆ—ใฎไธญใซๆŒ‡ๅฎšๆ–‡ๅญ—ใŒไธ€ใคไปฅไธŠๅญ˜ๅœจใ™ใ‚‹ใจใใ€ๆœ€ๅˆใซ่ฆ‹ๅฝ“ใŸใ‚‹ใฎใ ใ‘ใŒๅค‰ๆ›ดๅฏพ่ฑกใซใชใ‚Šใพใ™ใ€‚

ไพ‹ใˆใฐ ‘my_name_is_Ron’ใ‹ใ‚‰ใ‚ขใƒณใƒ€ใƒผใƒใƒผใ‚’ๅ…จ้ƒจ็ฉบ็™ฝใซใ™ใ‚‹ใŸใ‚replace(‘_’,’ ‘)ใซใ—ใฆใ‚‚็ตๆžœใฏโ€™my name_is_Ron’ใซใชใ‚Šใพใ™ใ€‚

ใชใฎใงใ€ๆ–‡ๅญ—ๅˆ—ใฎไธญใงๅญ˜ๅœจใ™ใ‚‹ๅ…จใฆใ‚‚ๆŒ‡ๅฎšๆ–‡ๅญ—ใ‚’ๅค‰ๆ›ใ—ใŸใ„ๆ™‚ใฏๆญฃ่ฆ่กจ็พใ‚’ไฝฟใ†ใจ่กŒใ‘ใพใ™ใ€‚

const mySentence = 'my name is:Ron';

mySentence.replace(':',' ');        //'my name is Ron'

const mySentence = 'my_name_is_Ron';

mySentence.replace('_',' ');      // 'my name_is_Ron'

//ๆญฃ่ฆ่กจ็พใงใ™ในใฆใฎๆ–‡ๅญ—ใ‚’ๅค‰ๆ›
mySentence.replace(/_/g, ' ');    // 'my name is Ron'

indexOfใฏๆŒ‡ๅฎšๆ–‡ๅญ—ใฎไฝ็ฝฎใ‚’่ฟ”ใ—ใพใ™ใ€‚

ใ“ใฎใƒกใ‚ฝใƒƒใƒ‰ใฏๆŒ‡ๅฎšๆ–‡ๅญ—ใฎๅ‰ใพใŸใฏๅพŒใงๆ–‡ๅญ—ๅˆ—ใ‚’ๅˆ‡ใ‚Šๅ–ใ‚‹ใจใๆœ‰็”จใชใ‚‚ใฎใงใ™ใ€‚

ใŸใจใˆใ€’Z001-03’ใ‹ใ‚‰ๅพŒใ‚ใฎ’03’ใ ใ‘ใ‚’ๆŠฝๅ‡บใ—ใŸใ„ใจใใ€indexOfใง’-‘ๆ–‡ๅญ—ใ‚’ๆŽขใ—ใ€่ฟ”ใ—ใฎindex +1ไฝ็ฝฎใ‹ใ‚‰ๆœ€ๅพŒใพใงใ‚ซใƒƒใƒˆใ™ใ‚‹ใจ’03’ใ‚’ๅˆ‡ใ‚Šๅ–ใ‚‹ใ“ใจใŒใงใใพใ™ใ€‚

ใ‚‚ใ—ๆ–‡ๅญ—ๅˆ—ใฎไธญๆŒ‡ๅฎšๆ–‡ๅญ—ใŒไธ€ใคไปฅไธŠใฎๅ ดๅˆใ€้ ญใ‹ใ‚‰ๆŽขใ—ๅง‹ใ‚ๆœ€ๅˆใซ่ฆ‹ๅฝ“ใŸใ‚‹ๆ–‡ๅญ—ไฝ็ฝฎใ‚’่ฟ”ใ—ใพใ™ใ€‚

ใงใ‚‚ใƒ‘ใƒฉใƒกใƒผใ‚ฟใซindexใ‚’ๆธกใ™ใจๆŒ‡ๅฎšใ•ใ‚ŒใŸไฝ็ฝฎใ‹ใ‚‰ๆŒ‡ๅฎšๆ–‡ๅญ—ใ‚’ๆŽขใ—ใพใ™ใ€‚

ๆณจๆ„็‚นใฏstart indexใ‚’ๆธกใ—ใฆใ‚‚่ฟ”ใ™ๅ€คใฏๅ…จไฝ“ใฎๆ–‡ๅญ—ๅˆ—ใ‹ใ‚‰ไฝ•็•ช็›ฎใงใ‚ใ‚‹ใจใ„ใ†ๆ•ฐๅญ—ใ‚’่ฟ”ใ—ใพใ™ใ€‚

ๅพŒใ‚ใ‹ใ‚‰ๆคœ็ดขใ™ใ‚‹ใฎใฏlastIndexOfใงใ€ๅพŒใ‚ใ‹ใ‚‰ๆœ€ๅˆใฎๆŒ‡ๅฎšๆ–‡ๅญ—ใฎไฝ็ฝฎใ‚’่ฟ”ใ—ใพใ™ใ€‚

ใ“ใฎๆ™‚ใ‚‚่ฟ”ใ™ๅ€คใฏ้ ญใ‹ใ‚‰ไฝ•็•ช็›ฎใงใ‚ใ‚‹ใจใ„ใ†ๆ•ฐๅญ—ใงใ™ใ€‚

ๆŒ‡ๅฎšๆ–‡ๅญ—ใŒใชใ‘ใ‚Œใฐ-1ใ‚’่ฟ”ใ—ใพใ™ใ€‚

const mySentence = 'Z001-03';

mySentence.indexOf('-');     // 4

mySentence.substring(mySentence.indexOf('-')+1);    // '03'

mySentence.indexOf('D');    // -1

const mySentence = 'Z001-03-02';

mySentence.indexOf('-');    // 4
mySentence.indexOf('-', 5);   // 7

mySentence.lastIndexOf('-')   // 7

testใฏไธ€่ˆฌ็š„ใซๆญฃ่ฆ่กจ็พใจไธ€็ท’ใซไฝฟใ„ใ€ๆธกใ™ๆ–‡ๅญ—ๅˆ—ใจๆฏ”่ผƒใ—ๆœ‰ๅŠนๆ€งใ‚’็ขบ่ชใ—ใพใ™ใ€‚

ใƒ‘ใ‚นใƒฏใƒผใƒ‰ใ€ใ‚ขใƒซใƒ•ใ‚กใƒ™ใƒƒใƒˆใ€็‰นๆฎŠๆ–‡ๅญ—ใ€็”Ÿๅนดๆœˆๆ—ฅใชใฉใฎๅฝขๅผๆคœๆŸปใซไฝฟใˆใพใ™ใ€‚

const mySentence = /a/;
const myWord = 'baby';

mySentence.test(myWord);   // true

/\d/.test('cookie');       // false \dใฏๆ•ฐๅญ—ใ‚’ๆ„ๅ‘ณ(ๆญฃ่ฆ่กจ็พ)
/\d/.test('cookie1');      // true

ไธŠใฎไพ‹ไปฅๅค–ใซใ‚‚ๅฑฑใปใฉใƒกใ‚ฝใƒƒใƒ‰ใŒๅคšใ„ใ—ใ€ใพใŸๆ–ฐใ—ใไฝœใ‚‰ใ‚Œใ‚‹ใƒกใ‚ฝใƒƒใƒ‰ใ‚‚ใŸใใ•ใ‚“ใ‚ใ‚Šใพใ™ใญใ€‚

ใพใŸๅฟ…่ฆใชๆฉŸ่ƒฝใฎใƒกใ‚ฝใƒƒใƒ‰ใŒใ‚ใ‚Œใฐ็ขบ่ชใ—ใฆใ„ใใพใ—ใ‚‡๏ผ

ใ‚ใ–ใƒผใ™๏ผ