728x90

<!DOCTYPE html>
<html lang="en">
<head>
  <script src="https://code.jquery.com/jquery-3.5.1.min.js"></script>
 <style>
 </style>
</head>
<body>
    <script>
      const a=true;
      const b=false;

      document.write(a+"<br>");

      const c=null; //값이 지정되지 않음 -> 참조하는 값이 없음
      document.write(typeof(c)+"<br>");

      const d=undefined; 
      //변수 선언 후 값을 할당하지 않은 상태 -> 공간자체가 없는 상태
      document.write(typeof(d)+"<br>");   
    </script>
</body>
</html>

<!DOCTYPE html>
<html lang="en">
<head>
  <script src="https://code.jquery.com/jquery-3.5.1.min.js"></script>
 <style>
 </style>
</head>
<body>
  <script>
    const user={
      name:'kim',
      age:43,
      man:true,
    };
    const post={
      title:"제목",
      content:"내용",
      user, //user:user 뜻임 //키의 이름과 값에 들어가는 변수의 이름이 같다면 생략가능
    } 

    user.name===user['name'];
    console.log(user.name);  //kim
    console.log(user['name']); //kim
    console.log(user.man);
    console.log(post.user.age);

    const user2={
      name:'lee',
    }

    //user2='hello';
    user2.man=false; //속성은 변경 가능
    console.log(user2);

    delete user2.man;
    console.log('man' in user2);

  </script>
</body>
</html>

 

익명함수, 화살표 함수

 

<!DOCTYPE html>
<html lang="en">
<head>
  <script src="https://code.jquery.com/jquery-3.5.1.min.js"></script>
 <style>
 </style>
</head>
<body>
  <script>
    //함수: 목적있는 작업을 수행하도록 설계된 독립된 모듈
    /*function cal(a,b){
      return (a+b)*2;
    }
    const n=cal(1,2);
    const n2=cal(2,3);*/
  ////////////////////////////////////////////////////
  //익명함수: 함수를 변수처럼 사용하는 익명함수
    const cal = function(a,b){
      return (a+b)*2;
    }
    document.write(cal(1,2) +"<br>");
////////////////////////////////////////////

    function func(a){
      return a+3;
    }
    const func3=a=>a+3;

    const func2=()=>{
      console.log('hi');
      return a+3;
    }
    const func4=()=>console.log('hi');

    let n=()=>alert('hi');
    
    let n2=(a,b)=>{
      let msg=`${a}, ${b}`;
      return msg;
    }
    document.write(n2(3,4));

  </script>
</body>
</html>

 

<!DOCTYPE html>
<html lang="en">
<head>
  <script src="https://code.jquery.com/jquery-3.5.1.min.js"></script>
 <style>
 </style>
</head>
<body>
  <script>
   
    let n=[];

    for(let i=0;i<6;i++){
      let lotto=Math.floor(Math.random()*44)+1;
      for(let j in n){
        if(lotto==n[j]){
          lotto=Math.floor(Math.random()*44)+1;
        }
      }
      n.push(lotto);
    }
    n.sort(function(a,b){
      return a-b; // 오름차순
      //return b-1 = 내림차순
    });
    document.write(n);

  </script>
</body>
</html>
728x90

+ Recent posts