Skip to content

Instantly share code, notes, and snippets.

@hoony-o-1
Created February 1, 2018 04:48
Show Gist options
  • Save hoony-o-1/d4f9500fc44c404a397a2495cc1d762b to your computer and use it in GitHub Desktop.
Save hoony-o-1/d4f9500fc44c404a397a2495cc1d762b to your computer and use it in GitHub Desktop.
React를 위한 JavaScript 기초
/**
* 1. let과 const의 차이
*/
let num1 = 1;
const num2 = 3;
num1 = 3;
// 성공
num2 = 4;
// 에러
/**
* 2. JavaScript 함수
*/
const num3 = 1;
const num4 = 3;
const num5 = add(num1, num2);
// addedNumber = 4
function add (a, b) {
return a + b;
}
/**
* 3. JavaScript Array와 메소드 활용하기
*/
const students = [{
name: '장승훈',
age: 20
}, {
name: '김지민',
age: 31
}, {
name: '전새암',
age: 13
}]
students.forEach(function (student, index) {
console.log(student.name + '의 나이는 ' + student.age + '세입니다.')
})
// '장승훈의 나이는 20세입니다.
// '김지민의 나이는 310세입니다.
// '전새암의 나이는 13세입니다.
/**
* 4. JavaScript의 콜백함수
*/
function getApi (callback) {
console.log('Start of Call GET Api')
window.setTimeout(function () {
if (callback) callback()
}, 1000)
console.log('End of Call GET Api')
}
getApi(function () {
console.log('Done!')
})
// Start of Call GET Api
// End of Call GET Api
// Done!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment