Blinking Hello Kitty Angel

javascript

์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ ํ…Œ์ŠคํŠธ - ๋ฐ์ดํ„ฐ ๋ถˆ๋Ÿฌ์˜ค๊ธฐ

xoouxa 2023. 3. 3. 19:37

โ€œ ์ง€์—ฐ๋˜๋Š” ํ”„๋กœ์ ํŠธ์— ์ธ๋ ฅ์„ ๋” ํˆฌ์ž…ํ•˜๋ฉด ์˜คํžˆ๋ ค ๋” ๋Šฆ์–ด์ง„๋‹ค. โ€

- Frederick Philips Brooks
Mythical Man-Month ์ €์ž
728x90

๐Ÿคท‍โ™‚๏ธ 01. ๋‹ค์Œ์˜ ์ถœ๋ ฅ๊ฐ’์„ ๋ณด๊ณ  ๋นˆ์นธ์„ ์ฑ„์šฐ์‹œ์˜ค ๐Ÿคท‍โ™‚๏ธ

{
    var x = 100; 
    var y = 200; 
    var z = "javascript"; 

    console.log(__);
    console.log(__);
    console.log(__);

    //100
    //200
    //300
}

๐Ÿ“ ๋ณ€์ˆ˜ x์— ์ˆซ์ž 100์„ ์ง€์ •ํ•จ 
    ๋ณ€์ˆ˜ y์— ์ˆซ์ž 200์„ ์ง€์ •ํ•จ

    ๋ณ€์ˆ˜ z์— ์ˆซ์ž javascript

 

โœ๐Ÿป x
      y
      x+y

 

 

๐Ÿคท‍โ™‚๏ธ 02. ๋‹ค์Œ์˜ ์ถœ๋ ฅ๊ฐ’์„ ๋ณด๊ณ  ๋นˆ์นธ์„ ์ฑ„์šฐ์‹œ์˜ค๐Ÿคท‍โ™‚๏ธ

{
    let x = 100;
    let y = 200;
    let z = "javascript";

    x = ___;   
    y = ___;
    z = ___;

    console.log(x);
    console.log(y);
    console.log(z);

    //300
    //400
    //jquery
}

๐Ÿ“ ๋ณ€์ˆ˜ x์— ์ˆซ์ž 300์œผ๋กœ ๋ณ€๊ฒฝ
    ๋ณ€์ˆ˜ y์— ์ˆซ์ž 200์œผ๋กœ ๋ณ€๊ฒฝ

    ๋ณ€์ˆ˜ z์— ๋ฌธ์ž "react"๋กœ ๋ณ€๊ฒฝ

 

โœ๐Ÿป 300
      400
      jquary

 

๐Ÿคท‍โ™‚๏ธ 03. ๋‹ค์Œ์˜ ์ถœ๋ ฅ๊ฐ’์„ ๋ณด๊ณ  ๋นˆ์นธ์„ ์ฑ„์šฐ์‹œ์˜ค๐Ÿคท‍โ™‚๏ธ

{
    let x = 100;
    let y = 200;
    let z = "javascript";

    x ___ 300;       
    y ___ 400;       
    z ___ "jquery";  

    console.log(x);
    console.log(y);
    console.log(z);

    //400
    //-200
    //javascriptjquery
}

๐Ÿ“ ๋ณ€์ˆ˜๋Š” ๋ฐ์ดํ„ฐ๋ฅผ ์ €์žฅ, ๋ณ€๊ฒฝ, ์ถ”๊ฐ€ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

    x = x + 300

    y = y - 400

    z = z + "jquary"

    

โœ๐Ÿป += 
      - =
      +=

๐Ÿคท‍โ™‚๏ธ 04. ๋‹ค์Œ์˜ ์ถœ๋ ฅ๊ฐ’์„ ๋ณด๊ณ  ๋นˆ์นธ์„ ์ฑ„์šฐ์‹œ์˜ค ๐Ÿคท‍โ™‚๏ธ

{
    const arr = ________();   

    arr[0] = 100;               
    arr[1] = 200;               
    arr[2] = "javascript";     

    console.log(arr[0]);
    console.log(arr[1]);
    console.log(arr[2]);

    //100
    //200
    //javascript
}

๐Ÿ“  new Array()๋Š” JavaScript์—์„œ ๋ฐฐ์—ด์„ ์ƒ์„ฑํ•˜๋Š” ๋ฐฉ๋ฒ• ์ค‘ ํ•˜๋‚˜์ž…๋‹ˆ๋‹ค.

    Array ์ƒ์„ฑ์ž ํ•จ์ˆ˜๋Š” ๊ธฐ๋ณธ์ ์œผ๋กœ ๋นˆ ๋ฐฐ์—ด์„ ์ƒ์„ฑํ•ฉ๋‹ˆ๋‹ค.

    ์ƒ์„ฑ์ž ํ•จ์ˆ˜์— ์ธ์ˆ˜๋ฅผ ์ „๋‹ฌํ•˜๋ฉด ํ•ด๋‹น ์ธ์ˆ˜์˜ ์ˆ˜๋งŒํผ์˜ ์š”์†Œ๋ฅผ ๊ฐ€์ง„ ๋ฐฐ์—ด์ด ์ƒ์„ฑ๋ฉ๋‹ˆ๋‹ค.

    ์˜ˆ๋ฅผ ๋“ค์–ด, new Array(3)์€ 3๊ฐœ์˜ ์š”์†Œ๋ฅผ ๊ฐ€์ง„ ๋นˆ ๋ฐฐ์—ด์„ ์ƒ์„ฑํ•ฉ๋‹ˆ๋‹ค.

    ๋ฐฐ์—ด ๋ฆฌํ„ฐ๋Ÿด์„ ์‚ฌ์šฉํ•˜๋ฉด ์ฝ”๋“œ๋ฅผ ๋” ๊ฐ„๊ฒฐํ•˜๊ณ  ๊ฐ€๋…์„ฑ ์žˆ๊ฒŒ ์ž‘์„ฑํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค

 

โœ๐Ÿป  new Array

    

 

๐Ÿคท‍โ™‚๏ธ 05. ๋‹ค์Œ์˜ ์ถœ๋ ฅ๊ฐ’์„ ๋ณด๊ณ  ๋นˆ์นธ์„ ์ฑ„์šฐ์‹œ์˜ค๐Ÿคท‍โ™‚๏ธ

{
    const arr = [___________________];    

    console.log(arr[0]);
    console.log(arr[1]);
    console.log(arr[2]);

    //100
    //200
    //javascript
}

๐Ÿ“   05๋ฒˆ์„ ์ข€ ๋” ๊ฐ„๊ฒฐํ•˜๊ฒŒ ์‚ฌ์šฉํ•˜๋ฉด
      new Array()์— ๋ฐ์ดํ„ฐ๋ฅผ ","๋กœ ๊ตฌ๋ถ„ํ•˜์—ฌ ์ €์žฅํ•˜๋Š” ๋ฐฉ๋ฒ•์ž…๋‹ˆ๋‹ค.

 

โœ๐Ÿป  new Array (100,200,"javascript")

 

 

๐Ÿคท‍โ™‚๏ธ 06. ๋‹ค์Œ์˜ ์ถœ๋ ฅ๊ฐ’์„ ๋ณด๊ณ  ๋นˆ์นธ์„ ์ฑ„์šฐ์‹œ์˜ค๐Ÿคท‍โ™‚๏ธ

{
    const obj = new Object();

    obj[0] = 100;
    obj[1] = 200;
    obj[2] = "javascript";

    console.log(______);
    console.log(______);
    console.log(______);

    //100
    //200
    //javascript
}

๐Ÿ“   ๊ฐ์ฒด(object)๋Š” ๋ฐ์ดํ„ฐ ๊ฐ’์„ ํ•„์š”ํ•œ ๋Œ€๋กœ ๋งŒ๋“ค์–ด ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๊ณ  ๊ฐ์ฒด์˜ ๋ฐ์ดํ„ฐ๋Š” ํ‚ค(์ด๋ฆ„) ๊ฐ’์œผ๋กœ

      ์ด๋ค„์ ธ ์žˆ์œผ๋ฉฐ ์ด๊ฒƒ์„ ์†์„ฑ์ด๋ผ ํ•ฉ๋‹ˆ๋‹ค.


โœ๐Ÿป  obj.[0]

       obj.[1]

       obj.[2]

 

๐Ÿคท‍โ™‚๏ธ 07. ๋‹ค์Œ์˜ ์ถœ๋ ฅ๊ฐ’์„ ๋ณด๊ณ  ๋นˆ์นธ์„ ์ฑ„์šฐ์‹œ์˜ค!(console.log๋ฅผ ์‚ฌ์šฉํ•  ๊ฒƒ) ๐Ÿคท‍โ™‚๏ธ

{
    const obj = new Object();
    
    obj.a = 100;
    obj.b = 200;
    obj.c = "javascript";

    _____________________
    _____________________
    _____________________

    //100
    //200
    //javascript
}

๐Ÿ“  ์—ฌ๋Ÿฌ ๊ฐœ์˜ ๋ฐ์ดํ„ฐ๋ฅผ ํ•˜๋‚˜์˜ ๋ณ€์ˆ˜์— ์ €์žฅํ•˜๊ณ  ๋ฐ์ดํ„ฐ๊ฐ€ ์ถ”๊ฐ€๋˜๋ฉด ์ถ”๊ฐ€ ๋œ ๋ฐ์ดํ„ฐ๋ฅผ ์‹๋ณ„ํ•ด

     ๊ฐ€์ ธ์˜ฌ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. 

     ex ) obj. ํ‚ค= ๊ฐ’;

 

โœ๐Ÿป  console.log(obj.a);

       console.log(obj.b);

       console.log(obj.c);

 

๐Ÿคท‍โ™‚๏ธ 08. ๋‹ค์Œ์˜ ์ถœ๋ ฅ๊ฐ’์„ ๋ณด๊ณ  ๋นˆ์นธ์„ ์ฑ„์šฐ์‹œ์˜ค ๐Ÿคท‍โ™‚๏ธ

{
    const obj = {____________________};

    console.log(obj.a);
    console.log(obj.b);
    console.log(obj.c);

    //100
    //200
    //javascript
}

๐Ÿ“  ์—ฌ๋Ÿฌ ๊ฐœ์˜ ๋ฐ์ดํ„ฐ๋ฅผ ํ•˜๋‚˜์˜ ๋ณ€์ˆ˜์— ์ €์žฅํ•˜๊ณ  ๋ฐ์ดํ„ฐ๊ฐ€ ์ถ”๊ฐ€๋˜๋ฉด ์ถ”๊ฐ€ ๋œ ๋ฐ์ดํ„ฐ๋ฅผ ์‹๋ณ„ํ•ด์„œ

     ๊ฐ€์ ธ์˜ฌ ์ˆ˜ ์žˆ๋‹ค. ex ) const obj = {ํ‚ค:๊ฐ’, ํ‚ค:๊ฐ’, ํ‚ค:๊ฐ’};

 

โœ๐Ÿป  {a: 100, b:200, c:"javascript"};

    

๐Ÿคท‍โ™‚๏ธ 09. ๋‹ค์Œ์˜ ์ถœ๋ ฅ๊ฐ’์„ ๋ณด๊ณ  ๋นˆ์นธ์„ ์ฑ„์šฐ์‹œ์˜ค๐Ÿคท‍โ™‚๏ธ

9. ๋‹ค์Œ์˜ ์ถœ๋ ฅ๊ฐ’์„ ๋ณด๊ณ  ๋นˆ์นธ์„ ์ฑ„์šฐ์‹œ์˜ค!
{
    const obj = [
        {a:100, b:200},
        {c:"javascript"}
    ];

    console.log(________);
    console.log(________);
    console.log(________);

    //100
    //200
    //javascript
}

๐Ÿ“  ๊ฐ์ฒด ์—ฌ๋Ÿฌ ๊ฐœ์˜ ๋ฐ์ดํ„ฐ๋ฅผ ํ•˜๋‚˜์˜ ๋ณ€์ˆ˜์— ์ €์žฅํ•˜๊ณ  ๋ฐ์ดํ„ฐ๊ฐ€ ์ถ”๊ฐ€๋˜๋ฉด ์ถ”๊ฐ€ ๋œ ๋ฐ์ดํ„ฐ๋ฅผ ์‹๋ณ„ํ•ด
     ๊ฐ€์ ธ์˜ฌ ์ˆ˜ ์žˆ๋‹ค.

     ๋ฐฐ์—ด ์•ˆ์— ๊ฐ์ฒด๊ฐ€ ์žˆ๋Š” ๋ฐฉ๋ฒ• ex) ์ถœ๋ ฅ : consol.log(obj[๋ฐฐ์—ด].๊ฐ์ฒด);

 

โœ๐Ÿป  obj[0]

       obj[1]

       obj[2]

 

๐Ÿคท‍โ™‚๏ธ 10. ๋‹ค์Œ์˜ ์ถœ๋ ฅ๊ฐ’์„ ๋ณด๊ณ  ๋นˆ์นธ์„ ์ฑ„์šฐ์‹œ์˜ค๐Ÿคท‍โ™‚๏ธ

{
    const obj = {
        a: 100,
        b: [200, 300],
        c: "javascript"
    }
    console.log(________);
    console.log(________);
    console.log(________);

    //200
    //300
    //200300
}

๐Ÿ“   ์ฒซ๋ฒˆ์งธ console.log()๋Š” ๊ฐ์ฒด(obj)์˜ b ํ”„๋กœํผํ‹ฐ์˜ ์ฒซ๋ฒˆ์งธ ์š”์†Œ(200)๋ฅผ ์ถœ๋ ฅํ•ฉ๋‹ˆ๋‹ค.

      ๋‘๋ฒˆ์งธ console.log()๋Š” ๊ฐ์ฒด(obj)์˜ b ํ”„๋กœํผํ‹ฐ์˜ ๋‘๋ฒˆ์งธ ์š”์†Œ(300)๋ฅผ ์ถœ๋ ฅํ•ฉ๋‹ˆ๋‹ค.

      ์„ธ๋ฒˆ์งธ console.log()๋Š” ๊ฐ์ฒด(obj)์˜ b ํ”„๋กœํผํ‹ฐ์˜ ๋ชจ๋“  ์š”์†Œ๋ฅผ ๋ฌธ์ž์—ด๋กœ ํ•ฉ์ณ์„œ ์ถœ๋ ฅํ•ฉ๋‹ˆ๋‹ค.

       ์ฆ‰, "200300"์ด ์ถœ๋ ฅ๋ฉ๋‹ˆ๋‹ค.

โœ๐Ÿป  obj.b[0]

       obj.b[1]

       obj.b

       

 

 

๐Ÿคท‍โ™‚๏ธ 11. ๋‹ค์Œ์˜ ์ถœ๋ ฅ๊ฐ’์„ ๋ณด๊ณ  ๋นˆ์นธ์„ ์ฑ„์šฐ์‹œ์˜ค๐Ÿคท‍โ™‚๏ธ

{
    const a = 100;
    const b = 200;
    const c = "javascript";

    const obj = { _________ }

    document.write(obj.a);
    document.write(obj.b);
    document.write(obj.c);

    //100
    //200
    //javascript
}

๐Ÿ“  ๊ฐ์ฒด

     ์—ฌ๋Ÿฌ ๊ฐœ์˜ ๋ฐ์ดํ„ฐ๋ฅผ ํ•˜๋‚˜์˜ ๋ณ€์ˆ˜์— ์ €์žฅํ•˜๊ณ  ๋ฐ์ดํ„ฐ๊ฐ€ ์ถ”๊ฐ€๋˜๋ฉด ์ถ”๊ฐ€ ๋œ ๋ฐ์ดํ„ฐ๋ฅผ ์‹๋ณ„ํ•ด
     ๊ฐ€์ ธ์˜ฌ ์ˆ˜ ์žˆ๋‹ค. ex) const ํ‚ค = ๊ฐ’; / consol

 

โœ๐Ÿป  {a, b, c};

 

๐Ÿคท‍โ™‚๏ธ 12. ๋‹ค์Œ์˜ ์ถœ๋ ฅ๊ฐ’์„ ๋ณด๊ณ  ๋นˆ์นธ์„ ์ฑ„์šฐ์‹œ์˜ค๐Ÿคท‍โ™‚๏ธ

{
    const obj = {
        a: 100,
        b: [200, ____],
        c: "javascript",
        d: _________(){
            document.write("javascript๊ฐ€ ์‹คํ–‰๋˜์—ˆ์Šต๋‹ˆ๋‹ค.");
        },
        e: function(){
            document.write( _______ + "๊ฐ€ ์‹คํ–‰๋˜์—ˆ์Šต๋‹ˆ๋‹ค.");    //๋ณ€์ˆ˜๊ฐ’ ์‚ฌ์šฉ
        },
        f: function(){
            document.write( _______ + "๊ฐ€ ์‹คํ–‰๋˜์—ˆ์Šต๋‹ˆ๋‹ค.");    //this๋ฅผ ์‚ฌ์šฉ
        }
    }

    document.write(obj.a);
    document.write(obj.b);
    document.write(obj.b[0]);
    document.write(obj.b[1]);
    document.write(obj.c);
    obj.d();
    obj.e();
    obj.f();

    //100
    //200,300
    //200
    //300
    //javascript
    //javascript๊ฐ€ ์‹คํ–‰๋˜์—ˆ์Šต๋‹ˆ๋‹ค.
    //javascript๊ฐ€ ์‹คํ–‰๋˜์—ˆ์Šต๋‹ˆ๋‹ค.
    //javascript๊ฐ€ ์‹คํ–‰๋˜์—ˆ์Šต๋‹ˆ๋‹ค.
}

๐Ÿ“  ๊ฐ์ฒด

     ๊ฐ์ฒด๋Š” ๋ฐ์ดํ„ฐ ๊ฐ’์„ ํ•„์š”ํ•œ๋Œ€๋กœ ๋งŒ๋“ค์–ด ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
     ๊ฐ์ฒด ์•ˆ์—” ํ•จ์ˆ˜์ธ ์‹คํ–‰๋ฌธ์ด ๋“ค์–ด๊ฐˆ ์ˆ˜ ์žˆ๋Š”๋ฐ, ์‹คํ–‰๋ฌธ์„ ์‹คํ–‰์‹œํ‚ฌ ๋•Œ ์‚ฌ์šฉํ•˜๋Š” ๋ฒ•์ž…๋‹ˆ๋‹ค.

 

โœ๐Ÿป  300

       function()

       obj.c

       this.c

 

๐Ÿคท‍โ™‚๏ธ 13. ๋‹ค์Œ ๊ฒฐ๊ด๊ฐ’์„ ์™„์„ฑํ•˜์‹œ์˜ค.๐Ÿคท‍โ™‚๏ธ

{
    for( let i=1; i<10; i++){
        if(i % 2 == 0) {
            document.write(i);
        }
    }
}

๐Ÿ“  ๋ฐ์ดํ„ฐ ์ดํŽ™ํŠธ

     for()๋ฌธ์„ ์ด์šฉํ•ด 1 - 100๊นŒ์ง€ ์ง์ˆ˜๋งŒ ์ถœ๋ ฅํ•˜๋Š” ์˜ˆ์ œ์ž…๋‹ˆ๋‹ค.

     ์ฆ๊ฐ ์—ฐ์‚ฐ์ž๋ฅผ ์ด์šฉ, i += 2๋Š” i = + 2์™€ ๊ฐ™์€ ์‹ (2์”ฉ ์ฆ๊ฐ€)

 

โœ๐Ÿป 2,4,6,8

 

๐Ÿคท‍โ™‚๏ธ 14. ๋‹ค์Œ ๊ฒฐ๊ด๊ฐ’์„ ์™„์„ฑํ•˜์‹œ์˜ค. ๐Ÿคท‍โ™‚๏ธ

{
    for( let i=1; i<10; i++){
        if( true ) {
            document.write(i);
        }
    }
}

๐Ÿ“  1๋ถ€ํ„ฐ 9๊นŒ์ง€์˜ ์ˆ˜๋ฅผ ์ถœ๋ ฅํ•˜๋Š” ๋ฐ˜๋ณต๋ฌธ์ž…๋‹ˆ๋‹ค.

     ๊ทธ๋Ÿฌ๋‚˜ if๋ฌธ ์•ˆ์— ํ•ญ์ƒ true๊ฐ€ ๋“ค์–ด๊ฐ€๋ฏ€๋กœ, i๊ฐ€ 1๋ถ€ํ„ฐ 9๊นŒ์ง€ ๋ชจ๋‘ ์ถœ๋ ฅ๋ฉ๋‹ˆ๋‹ค.

 

โœ๐Ÿป 1,2,3,4,5,6,7,8,9

 

๐Ÿคท‍โ™‚๏ธ 15. ๋‹ค์Œ ๊ฒฐ๊ด๊ฐ’์„ ์™„์„ฑํ•˜์‹œ์˜ค๐Ÿคท‍โ™‚๏ธ 

{
    const func = function(){
        document.write("ํ•จ์ˆ˜๊ฐ€ ์‹คํ–‰๋˜์—ˆ์Šต๋‹ˆ๋‹ค.");
    }
    func();
}

๐Ÿ“  ์ต๋ช… ํ•จ์ˆ˜

     ๋ณ€์ˆ˜๋Š” ๋ฐ์ดํ„ฐ๋ฅผ ์ €์žฅํ•˜๋Š” "์ €์žฅ์†Œ" ์ด๋ฉฐ ์ด ์ €์žฅ์†Œ์—” ์ˆซ์ž, ๋ฌธ์ž, ํ•จ์ˆ˜, ๊ฐ์ฒด ๋“ฑ์„ ์ €์žฅํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

 

โœ๐Ÿป ์‹คํ–‰๋˜์—ˆ์Šต๋‹ˆ๋‹ค.

 

๐Ÿคท‍โ™‚๏ธ 16. ๋‹ค์Œ ๊ฒฐ๊ด๊ฐ’์„ ์™„์„ฑํ•˜์‹œ์˜ค.๐Ÿคท‍โ™‚๏ธ

{
    if( 1 ){
        document.write("์กฐ๊ฑด๋ฌธ์ด ์‹คํ–‰๋˜์—ˆ์Šต๋‹ˆ๋‹ค.(true)");
    } else {
        document.write("์กฐ๊ฑด๋ฌธ์ด ์‹คํ–‰๋˜์—ˆ์Šต๋‹ˆ๋‹ค.(false)");
    }
}

๐Ÿ“  if๋ฌธ

    ์œ„ ์ฝ”๋“œ๋Š” JavaScript์—์„œ ์กฐ๊ฑด๋ฌธ(if๋ฌธ)์ด ์–ด๋–ป๊ฒŒ ๋™์ž‘ํ•˜๋Š”์ง€๋ฅผ ๋ณด์—ฌ์ฃผ๊ธฐ ์œ„ํ•œ ์˜ˆ์ œ์ž…๋‹ˆ๋‹ค.

    if๋ฌธ์˜ ์กฐ๊ฑด์‹์ด 1๋กœ, JavaScript์—์„œ๋Š” 0 ์ด์™ธ์˜ ๋ชจ๋“  ๊ฐ’์ด true๋กœ ํ‰๊ฐ€๋ฉ๋‹ˆ๋‹ค. ๋”ฐ๋ผ์„œ, if๋ฌธ์˜ ์กฐ๊ฑด์‹์€ ์ฐธ์ด ๋ฉ๋‹ˆ๋‹ค.

    ๋”ฐ๋ผ์„œ, ์ฝ”๋“œ ์‹คํ–‰ ๊ฒฐ๊ณผ๋Š” "์กฐ๊ฑด๋ฌธ์ด ์‹คํ–‰๋˜์—ˆ์Šต๋‹ˆ๋‹ค.(true)"๊ฐ€ ์ถœ๋ ฅ๋ฉ๋‹ˆ๋‹ค.

 

โœ๐Ÿป  ์กฐ๊ฑด๋ฌธ์ด ์‹คํ–‰๋˜์—ˆ์Šต๋‹ˆ๋‹ค.(true)

 

๐Ÿคท‍โ™‚๏ธ 17. ๋‹ค์Œ ๊ฒฐ๊ด๊ฐ’์„ ์™„์„ฑํ•˜์‹œ์˜ค.๐Ÿคท‍โ™‚๏ธ

{
    let num = 10;

    if( num == 100 ){
        document.write("์กฐ๊ฑด๋ฌธ์ด ์‹คํ–‰๋˜์—ˆ์Šต๋‹ˆ๋‹ค.(1)");
        if( num == 100 ){
            document.write("์กฐ๊ฑด๋ฌธ์ด ์‹คํ–‰๋˜์—ˆ์Šต๋‹ˆ๋‹ค.(2)");
            if( num == 100){
                document.write("์กฐ๊ฑด๋ฌธ์ด ์‹คํ–‰๋˜์—ˆ์Šต๋‹ˆ๋‹ค.(3)");
            }
        }
    } else {
        document.write("์กฐ๊ฑด๋ฌธ์ด ์‹คํ–‰๋˜์—ˆ์Šต๋‹ˆ๋‹ค.(4)");
    }
}

๐Ÿ“  ์ค‘์ฒฉ๋œ(if๋ฌธ ์•ˆ์— if๋ฌธ์ด ์žˆ๋Š”) ์กฐ๊ฑด๋ฌธ

    num ๋ณ€์ˆ˜์˜ ๊ฐ’์ด 10์œผ๋กœ, if๋ฌธ์˜ ์กฐ๊ฑด์‹ num == 100์€ ๊ฑฐ์ง“(false)์ด๋ฏ€๋กœ, else ๋ธ”๋ก์ด ์‹คํ–‰๋ฉ๋‹ˆ๋‹ค.

    ๋”ฐ๋ผ์„œ, ์ฝ”๋“œ ์‹คํ–‰ ๊ฒฐ๊ณผ๋Š” "์กฐ๊ฑด๋ฌธ์ด ์‹คํ–‰๋˜์—ˆ์Šต๋‹ˆ๋‹ค.(4)"๊ฐ€ ์ถœ๋ ฅ๋ฉ๋‹ˆ๋‹ค.

 

โœ๐Ÿป ์กฐ๊ฑด๋ฌธ์ด ์‹คํ–‰๋˜์—ˆ์Šต๋‹ˆ๋‹ค.(4)

 

๐Ÿคท‍โ™‚๏ธ 18. ๋‹ค์Œ ๊ฒฐ๊ด๊ฐ’์„ ์™„์„ฑํ•˜์‹œ์˜ค.๐Ÿคท‍โ™‚๏ธ

{
    let num = 10;

    (num == 100) ? document.write("true") : document.write("false");
}

๐Ÿ“  ์‚ผํ•ญ ์—ฐ์‚ฐ์ž(ternary operator)๋ฅผ ์‚ฌ์šฉ

    num ๋ณ€์ˆ˜์˜ ๊ฐ’์ด 10์œผ๋กœ, num == 100์€ ๊ฑฐ์ง“(false)์ด๋ฏ€๋กœ, false์ธ ๊ฒฝ์šฐ์— ๋Œ€ํ•œ ํ‘œํ˜„์‹์ธ document.write("false")            ๊ฐ€  ์‹คํ–‰๋ฉ๋‹ˆ๋‹ค.

    ๋”ฐ๋ผ์„œ, ์ฝ”๋“œ ์‹คํ–‰ ๊ฒฐ๊ณผ๋Š” "false"๊ฐ€ ์ถœ๋ ฅ๋ฉ๋‹ˆ๋‹ค.

 

โœ๐Ÿป  false

 

๐Ÿคท‍โ™‚๏ธ19. ๋‹ค์Œ ๊ฒฐ๊ด๊ฐ’์„ ์™„์„ฑํ•˜์‹œ์˜ค ๐Ÿคท‍โ™‚๏ธ 

{
    let num = 0;
    while( num <= 5 ){
        document.write( num + ". ๋ฐ˜๋ณต๋ฌธ์ด ์‹คํ–‰๋˜์—ˆ์Šต๋‹ˆ๋‹ค.");  
        num++;
    }
}

๐Ÿ“  while๋ฌธ์„ ์‚ฌ์šฉํ•˜์—ฌ ๋ฐ˜๋ณต๋ฌธ(loop)์„ ์‹คํ–‰

     num ๋ณ€์ˆ˜์˜ ๊ฐ’์ด 0์œผ๋กœ ์ดˆ๊ธฐํ™”๋˜๊ณ , while๋ฌธ์˜ ์กฐ๊ฑด์‹ num <= 5์€ num์ด 5๋ณด๋‹ค

     ์ž‘๊ฑฐ๋‚˜ ๊ฐ™์„ ๋•Œ ์ฐธ(true)์ด๋ฏ€๋กœ, while๋ฌธ์ด ์‹คํ–‰๋ฉ๋‹ˆ๋‹ค.

     ๊ทธ๋ฆฌ๊ณ  num ๋ณ€์ˆ˜๋ฅผ 1 ์ฆ๊ฐ€์‹œํ‚ต๋‹ˆ๋‹ค.

     ์ด๋ ‡๊ฒŒ ๋ฐ˜๋ณต์ ์œผ๋กœ document.write() ํ•จ์ˆ˜๋ฅผ ํ˜ธ์ถœํ•˜๋ฉด์„œ num ๋ณ€์ˆ˜์˜ ๊ฐ’์„ ์ถœ๋ ฅํ•˜๊ณ ,

      num ๋ณ€์ˆ˜๋ฅผ 1์”ฉ ์ฆ๊ฐ€์‹œํ‚ค๋ฉด์„œ while๋ฌธ์„ ๋ฐ˜๋ณต ์‹คํ–‰ํ•ฉ๋‹ˆ๋‹ค.

      num ๊ฐ’์ด 6์ด ๋˜๋ฉด while๋ฌธ์˜ ์กฐ๊ฑด์‹์ด ๊ฑฐ์ง“(false)์ด ๋˜๋ฏ€๋กœ, ๋ฐ˜๋ณต๋ฌธ์ด ์ข…๋ฃŒ๋ฉ๋‹ˆ๋‹ค.

 

โœ๐Ÿป  0. ๋ฐ˜๋ณต๋ฌธ์ด ์‹คํ–‰๋˜์—ˆ์Šต๋‹ˆ๋‹ค.

       1. ๋ฐ˜๋ณต๋ฌธ์ด ์‹คํ–‰๋˜์—ˆ์Šต๋‹ˆ๋‹ค.

       2. ๋ฐ˜๋ณต๋ฌธ์ด ์‹คํ–‰๋˜์—ˆ์Šต๋‹ˆ๋‹ค.

       3. ๋ฐ˜๋ณต๋ฌธ์ด ์‹คํ–‰๋˜์—ˆ์Šต๋‹ˆ๋‹ค.

       4. ๋ฐ˜๋ณต๋ฌธ์ด ์‹คํ–‰๋˜์—ˆ์Šต๋‹ˆ๋‹ค.

       5. ๋ฐ˜๋ณต๋ฌธ์ด ์‹คํ–‰๋˜์—ˆ์Šต๋‹ˆ๋‹ค.

 

๐Ÿคท‍โ™‚๏ธ20. ๋‹ค์Œ ๊ฒฐ๊ด๊ฐ’์„ ์™„์„ฑํ•˜์‹œ์˜ค.๐Ÿคท‍โ™‚๏ธ

{
    const str = [100, 200, 300, 400, 500];

    str.forEach((element, index, array) =>l {
        document.write(element);
        document.write(index);
        document.write(array);
    });
}

๐Ÿ“  ๋ฐฐ์—ด(str)์— forEach ๋ฉ”์„œ๋“œ๋ฅผ ํ˜ธ์ถœ

    ๋ฐฐ์—ด์˜ ๊ฐ ์š”์†Œ(element)์™€ ํ•ด๋‹น ์š”์†Œ์˜ ์ธ๋ฑ์Šค(index),

    ๊ทธ๋ฆฌ๊ณ  ์ „์ฒด ๋ฐฐ์—ด(array)์„ ์ถœ๋ ฅํ•˜๋Š” ์ฝ”๋“œ์ž…๋‹ˆ๋‹ค.

 

โœ๐Ÿป 1000100201300400400500[100, 200, 300, 400, 500]

 

 

โœจ ๊ฐ์‚ฌํ•ฉ๋‹ˆ๋‹ค.