본문 바로가기

function3

Java Script - this this - 자신이 속한 객체 또는 생성할 인스턴스를 가르키는 자기 참조 변수이다. console.log(this); function test(){ console.log(this); } test(); 아무것도 없는 상태의 this는 window 객체를 나타낸다. let employee = { name : "Lee", num : 224, serial: function(){ return this.num + this.name; } }; console.log(employee.serial()); 오브젝트 안의 this는 오브젝트를 나타낸다. 즉, employee.num, employee.name과 같은 의미이다. Check 여기서의 this는 button을 의미한다. Check2 1 2 3 function cal.. 2022. 12. 11.
Java Script - 문자열 메소드 String method string - 문자열과 관련된 함수 let text = "Hello world"; console.log(text.length); console.log(text.indexOf("world")); console.log(text.lastIndexOf("hello")); console.log(text.search("world")); console.log(text.charAt(3)); length - 문자열의 길이를 구한다. indexOf - 해당 파라미터를 찾아 최초 문자의 인덱스를 반환한다. 찾지 못하면 -1을 반환한다. lastIndexOf - indexOf와 같은 역할을 한다. 하지만 뒤에서부터 검사해 나오는 문자의 인덱스를 반환한다. search - indexOf와 같은 역할을 한다. 하지만 검사의 시.. 2022. 12. 5.
Java Script - 함수 function 함수는 같은 코드를 많이 작성할 때 사용할 수 있다. 함수를 작성하면 이후에 함수만 호출하면 된다. function employee(salary){ let rank = 0.4; let incentive = salary * rank; return incentive; } let incentive = employee(400); console.log(incentive); employee라는 함수를 선언하고 그 안에 코드를 작성한다. 같은 작업을 많이 할 경우, 함수만 불러와 변수만 바꾸면 쉽게 값을 얻을 수 있다. return 으로 반환할 값을 정할 수 있지만 없는 경우도 있다. 2022. 12. 5.