220510 생활코딩 - JavaScript 2

연주·2022년 5월 10일
0

TIL

목록 보기
2/37

생활코딩 - JavaScript

✔ 함수 (Function)

<script>
function 원하는이름() {
						//내용
}
</script>
 <script>
        function two(){
          document.write('<li>2-1</li>');
          document.write('<li>2-2</li>');
        }
        document.write('<li>1</li>');
        two();
        document.write('<li>3</li>');
        two();
      </script>

✔ Prameter & Argument 매개변수 & 인자

 <script>
        function onePlusOne(){
          document.write(1+1+'<br>')
        }
        onePlusOne();
        function sum(left,right){ // left, right는 매개변수
          document.write(left+right+'<br>');
        }
        sum(2,3); // 5  2,3은 인자
        sum(3,4); // 7
      </script>
  • 매개변수와 인자로 입력

✔ Return

	  <script>
        function sum2(left, right){
        return left+right;
      }
      document.write(sum2(2,3)+'<br>');
      document.write('<div style="color:red">'+sum2(2,3)+'</div>');
      document.write('<div style="font-size:3rem;">'+sum2(2,3)+'</div>');
      </script>
  • retrun은 출력

✔ Object 객체

    <script>
    var coworkers = {
        "programmer":"egoing",
        "designer":"leezche" 
        };
    </script>
  • 중괄호로 표현

✔ 객체와 반복문

    <script>
        for(var key in coworkers) {
          document.write(coworkers[key]+'<br>');
        }
      </script>
  • coworkers 안에 값을 가져오는 반복문

✔ property & Method

		<script>
        coworkers.showAll = function(){
          for(var key in this) {
            document.write(key+':'+this[key]+'<br>');
          }
        }
        coworkers.showAll();
      </script>
  • 객체에 소속된 함수 메소드
  • 객체에 소속된 변수 프로퍼티

💬 하루 되돌아보기

함수와 객체를 배웠는데 한번에 이해가 잘되지 않아서
몇 번을 돌려보고 돌려봤다.
당장의 활용능력은 조금 부족하지만 반복 학습으로 완벽히 이해해야겠다!

profile
성장중인 개발자🫰

0개의 댓글