Front-end
-
[javascript] 삼항연산자Front-end/Javascript 2020. 5. 27. 16:00
삼항연산자는 if와 switch처럼 조건문을 처리하는 연산자이다. 일반적으로 if 조건문의 축약형으로 사용되며, 세개의 문장으로 구성된다. 조건문 ? 표현문1 : 표현문2 조건문은 반드시 결과가 참(true)과 거짓(false)로 반환되어야 한다. 그리고 그 결과가 true면 표현문1을 실행하고, false이면 표현문2를 실행한다. ? 를 if 라 생각하고 : 를 else 라고 생각하면 좀 더 이해가 쉬울 것이다. 예시 var condition = 5 > 10; condition ? console.log('Left') : console.log('Right'); 결과값 Right
-
[javascript] 숫자형에 대해서 (Infinity, NaN)Front-end/Javascript 2020. 5. 27. 14:45
자바스크립트에서 숫자형(Number)이란 숫자 형태를 가진 데이터를 의미한다. 정수, 부동소수점, 작은 수, 큰 수등 여러유형의 숫자를 숫자형(Number) 하나로 정의한다. 이외에도 자바스크립트에서는 Infinity , NaN 값이 있다. 앞으로 나올 내용은 Infinity, NaN에 더 중점을 두어 포스팅할 예정이다. Infinity 말 그대로 무한대의 숫자형을 말한다. ECMA Script3 까지는 이 변수들의 값을 수정할 수 있었지만 ES5부터 수정할 수 없는 읽기 전용 상수로 바뀌었다. 더보기 console.log(Infinity); console.log(1 / Infinity); + Infinity로 나누면 무슨 값이든 0이 된다. 결과값 더보기 Infinity 0 NaN 'Not a Numb..
-
[javascript] hasOwnProperty를 통해 객체안에 속성여부 확인Front-end/Javascript 2020. 5. 26. 14:18
EX-1) var store = {snack:1000, flower:5000, beverage:2000}; for (var item in store){ if(!store.hasOwnProperty(item)) continue; console.log(item + ' 는 가격이'+store[item]+' 입니다.') } 위 코드는 store 객체를 순환하는 for - in 반복문 이다. 매 반복마다 hasOwnProperty를 이용하여 store 객체에 item 키 정보가 있는지 확인한다. 없으면 continue(계속진행) 를 통해 아래 코드는 실행하지않고 다음 순서로 넘어간다. 결과값 snack 는 가격이1000 입니다. flower 는 가격이5000 입니다. beverage 는 가격이2000 입니다. *..
-
form 태그 사용법Front-end/Html 2019. 11. 27. 00:14
폼태그 안에서 버튼을 2개이상 할때 1개만 서브밋타입 (버튼 3개씩 만들지 않음 대체로 span태그로 btn 클래스 써서 버튼처럼 보이게 함) 나머지는 버튼 근데 버튼형태인걸로 폼태그의 주소를 바꿔서 다른 액션페이지로 쏴야한다면 js로 form 태그의 action 속성을 변경하고 서브밋 해주면 된다.! 메인상세 $(function() { $("#detail").click(function() { $("#frm").attr("action", "/detail.do"); $("#frm").submit(); }); });