수

nodejs 기초문법 - 조건문 반복문

· 2019-01-12 (토) 23:08:42 · 3046

기초문법

 

다. 조건문

javascript 에는 조건문으로 if 와 switch 가 있는데 이 강좌에서는 if 만 사용하도록 하겠습니다.
조건문의 구조는 타 언어와 유사합니다.
var a = 10;

if (a > 11) {
    console.log('a가 11보다 큽니다'); 
} else if(a == 11) {
    console.log('a가 11과 같습니다');
} else {
    console.log('a가 11보다 작습니다');
}
* console은 node.js 에서 콘솔화면에 로그를 사용하기 위한 내장객체이고, 멤버변수인 log('내용')로 로그를 출력할 수 있습니다.

 

라. 반복문

반복문에는 for 와 while, do ~ while 이 있습니다. 이 강좌에서는 while 문만 사용하겠습니다.
// 0부터 9까지 출력하는 while문
var i=0;
while(i < 10) {
    console.log("for : i의 값은="+i);
    i=i+1;
}

|
댓글을 작성하시려면 로그인이 필요합니다.

개발자팁

5,403건

개발과 관련된 유용한 정보를 공유하세요. 질문은 QA에서 해주시기 바랍니다.

+
분류 제목 글쓴이 날짜 조회
PHP 19-06-24 조회 3,211
PHP 19-06-09 조회 3,828
MySQL 19-04-01 조회 4,886
jQuery 19-03-20 조회 4,272
node.js 19-02-12 조회 3,373
node.js 19-02-12 조회 3,113
node.js 19-02-12 조회 3,375
node.js 19-02-07 조회 3,346
node.js 19-02-07 조회 3,088
node.js 19-02-07 조회 3,226
node.js 19-02-04 조회 2,972
node.js 19-02-04 조회 2,944
node.js 19-02-04 조회 3,390
node.js 19-01-31 조회 2,496
node.js 19-01-31 조회 2,651
node.js 19-01-31 조회 3,123
node.js 19-01-28 조회 2,912
node.js 19-01-28 조회 2,977
node.js 19-01-28 조회 2,816
node.js 19-01-22 조회 3,166
node.js 19-01-22 조회 2,903
node.js 19-01-22 조회 3,361
node.js 19-01-16 조회 2,778
node.js
[node.js]
19-01-16 조회 2,672
node.js 19-01-16 조회 9,348
node.js 19-01-12 조회 4,424
node.js 19-01-12 조회 3,047
node.js 19-01-12 조회 3,169
node.js 19-01-11 조회 2,717
node.js 19-01-11 조회 4,073