삼항연산자 if else문

삼항연산자 if else문

QA

삼항연산자 if else문

본문

안녕하세요 고수님들! 아직 초보라 많이 배우는 중인 주니어입니다! 다른게 아니라 공부하던 중 삼항연산자가 나왔는데 이것을 제이쿼리 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으로 대입한다 입니다.

답변을 작성하시기 전에 로그인 해주세요.
전체 603
QA 내용 검색

회원로그인

(주)에스아이알소프트 / 대표:홍석명 / (06211) 서울특별시 강남구 역삼동 707-34 한신인터밸리24 서관 1404호 / E-Mail: admin@sir.kr
사업자등록번호: 217-81-36347 / 통신판매업신고번호:2014-서울강남-02098호 / 개인정보보호책임자:김민섭(minsup@sir.kr)
© SIRSOFT