삼항연산자 if else문

삼항연산자 if else문

QA

삼항연산자 if else문

답변 2

본문

안녕하세요 고수님들! 아직 초보라 많이 배우는 중인 주니어입니다! 다른게 아니라 공부하던 중 삼항연산자가 나왔는데 이것을 제이쿼리 ifelse문으로 다시 해석하고 싶어서 여쭤봅니다! 혹시 아시는 고수님들 계시면 해석 부탁드립니다!! 감사합니다

 


const target = start.childNodes[goTop] ? start.childNodes[goTop].childNodes[0].childNodes[goLeft] : null;

 


const dir = temp_block.direction + 1 < 4 ? temp_block.direction + 1 : 0;

이 질문에 댓글 쓰기 :

답변 2


//const target = start.childNodes[goTop] ? start.childNodes[goTop].childNodes[0].childNodes[goLeft] : null;
 
let target = null;
if (start.childNodes[goTop] != null) {
    target = start.childNodes[goTop].childNodes[0].childNodes[goLeft];
}

 


//const dir = temp_block.direction + 1 < 4 ? temp_block.direction + 1 : 0;
 
let dir = 0;
if (temp_block.direction + 1 < 4) {
    dir = temp_block.direction + 1;
}
const target = start.childNodes[goTop] ? start.childNodes[goTop].childNodes[0].childNodes[goLeft] : null;

target 값은 start.childNodes[goTop] 값이 있으면 start.childNodes[goTop].childNodes[0].childNodes[goLeft] 값을 대입하고 start.childNodes[goTop] 값이 없으면 null 값을 대입 한다 입니다.

 

const dir = temp_block.direction + 1 < 4 ? temp_block.direction + 1 : 0;

dir 값은 (temp_block.direction + 1) 값이 < 4 4보다 작으면 (temp_block.direction + 1)의 값을 대입하고 그 외에는 0으로 대입한다 입니다.

답변을 작성하시기 전에 로그인 해주세요.
QA 내용 검색
질문등록
전체 136
© SIRSOFT
현재 페이지 제일 처음으로