-
자바스크립트 thisjavascript 2020. 5. 22. 18:06
When a regular function code happens, then the default object is the window object, this 키워드가 일반 function 이나 그냥 불렸을 때는 window를 의미한다. 따라서 전역 객체로 정의되어 있는 것을 this.a 이런식으로 불러온다. 하지만 오브젝트 안의 메소드안에 this 가 쓰였을때의 this는 그 오브젝트를 의미하게 된다. var a = 1; function callA(){ var a = 2; console.log(this.a);//출력값 : 1//this.a이기 때문에 window에 전역변수로 선언된 a가 호출됨 console.log(a);//출력값 : 2//callA에 지역변수로 선언된 a가 호출됨 } callA(); ..
-
자바스크립트 Objectjavascript 2020. 5. 22. 03:47
/** * Objects and properties */ //Object literal var john = { firstName : 'John', lastName : 'Smith', birthYear : 1990, family : ['Jane', 'Mark', 'Bob', 'Emily'], job : 'teacher', isMarried : false } console.log(john.firstName); console.log(john['lastName']);//이런 식으로 접근하는 것도 가능하다. var x = 'birthYear'; console.log(john['birthYear']); john.job = 'designer'; console.log(john['job']); john['isMarrie..
-
자바스크립트 예제javascript 2020. 5. 22. 01:28
자바스크립트를 이용해 1)음식값을 입력받고 2)음식의 가격범주에 따라 팁을 정하고 3)음식값과 팁을 합쳐 4)각각의 총합 (총 음식값, 총 팁, 음식과 팁을 합친 값의 총계)를 보여주는 예제를 만들어 보았다. Udemy - The Complete JavaScript Course 2020 : Build Real Projects!과정의 Challenge3 과정이다. 아래 코드에 문제와 내가 해결한 답을 모두 적었다. /***************************** * CODING CHALLENGE 3 */ /* John and his family went on a holiday and went to 3 different restaurants. The bills were $124, $48 and $26..
-
자바스크립트 Truthy and Falsy values, equality operatorsjavascript 2020. 5. 21. 03:10
falsy value is a value that is considered false when evaluated falsy values : undefined, null, 0, ''(비어있는 문자), NaN All of this five different values here will be converted to false when evaluated in a true/false condition truthy value is a value that is considered true when in evaluated in an if/else statement condition. So, basically, it's all the values that are not falsy. truthy values : NOT ..
-
switch(true)javascript 2020. 5. 21. 02:19
보통 switch문을 쓸 때 switch(조건){ case '사과' : console.log('사과 냠냠'); break; case '바나나' : console.log('바나나 냠냠'); break; case '꿩' : case '알' : console.log('꿩도먹고 알도먹고');//조건에 '꿩'이나 '알'이 들어갔을 때.(둘다 걸림) break; default : console.log('밥'); } 이런식으로 조건당 케이스가 걸리는 줄 알았는데 switch(true){ case age = 13 && age = 13 && age < 20"); break; case age..
-
자바스크립트 연산자 우선순위javascript 2020. 5. 18. 22:39
https://developer.mozilla.org/ko/docs/Web/JavaScript/Reference/Operators/%EC%97%B0%EC%82%B0%EC%9E%90_%EC%9A%B0%EC%84%A0%EC%88%9C%EC%9C%84 연산자 우선순위 연산자 우선순위는 연산자를 실행하는 순서를 결정합니다. 우선순위가 높은 연산자가 먼저 실행됩니다. developer.mozilla.org 우선순위가 높을수록 먼저 실행된다. (우선순위 21이 우선순위 1보다 먼저 실행된다.)
-
자바스크립트 함수(계속 업데이트 예정)javascript 2020. 5. 18. 03:07
prompt() : 사용자에게 값을 입력 받을 수 있는 alert창을 띄운다. var question = prompt("What is your name?"); console.log(question);typeof 변수명 : 변수의 타입을 알려준다. var ageJohn, ageMark; ageJohn = 28; ageMark = 33; //Logical operator var johnOlder = ageJohn > ageMark; console.log(johnOlder); //typeof operator console.log(typeof johnOlder); //boolean console.log(typeof ageJohn); //number console.log(typeof 'Mark is old..
-
자바스크립트 데이터타입javascript 2020. 5. 18. 02:50
자바스크립트의 데이터 타입 Number : 정수와 소수등 모든 숫자 String Boolean Undefined : 밸류를 아직 가지고 있지 않은 데이터 타입. 변수는 선언했지만 값은 지정해 주지 않은 것. Null : 의도적으로 null 선언을 해준다. 자바스크립트에서는 자동으로 데이터 타입을 설정해준다. 이것은 코딩시간을 줄여주는 등 장점이 될 수 있지만 버그를 잡기 어렵다는 단점이 될 수도 있다. 변수를 선언할 때는 변수이름 맨 앞에 숫자나 (_와$를제외한)특수문자가 올 수 없다. 또 자바스크립트 키워드가 오면 안된다. https://webclub.tistory.com/1 도참조 undefined와 null의 차이점 undefined vs null 이 두 타입은 모두 자바스크립트에서 '값이 없음'을..