Skip to content

Instantly share code, notes, and snippets.

View khg0712's full-sized avatar
🎯
Focusing

Hugo Kim khg0712

🎯
Focusing
View GitHub Profile
@khg0712
khg0712 / JS-object-type-Example7.js
Created May 3, 2018 13:45
객체와 ν”„λ‘œν† νƒ€μž… 관계 μ˜ˆμ‹œ
var cat = {
name: 'James',
age: 2
};//cat 객체 생성
console.log(cat.toString());//[object Object] 좜λ ₯
console.dir(cat);
@khg0712
khg0712 / JS-array-type-Example1.js
Last active May 12, 2018 14:18
λ°°μ—΄ 생성 및 μ ‘κ·Ό μ˜ˆμ‹œ
//Array μƒμ„±μžλ‘œ λ°°μ—΄ 생성
var a = new Array(1);//μƒμ„±μžμ˜ μΈμžκ°€ ν•˜λ‚˜μΌ 땐 ν•΄λ‹Ή μΈμžκ°€ λ°°μ—΄μ˜ 크기가 λœλ‹€.
var b = new Array(1,2,3,4);//μƒμ„±μžμ˜ μΈμžκ°€ μ—¬λŸ¬ 개일 땐 μΈμžλ“€μ΄ λ°°μ—΄μ˜ μš”μ†Œκ°€ λœλ‹€.
//λ°°μ—΄ λ¦¬ν„°λŸ΄λ‘œ λ°°μ—΄ 생성
var c = [1,2,3];
console.log(a[0],a[1]);//undefined, undefined 좜λ ₯
console.log(b[0],b[1]);//1 2 좜λ ₯
console.log(c[0],c[1]);//1 2 좜λ ₯
@khg0712
khg0712 / JS-array-type-Example2.js
Created May 12, 2018 14:25
λ°°μ—΄ 생성 예제 2
var a = [1,2,3,,4];//[1,2,3,empty,4] λ°°μ—΄ 생성
var b = [1,2,3,,,4];//[1,2,3,empty,empty,4] λ°°μ—΄ 생성
var c = [1,2,3,4,,];//[1,2,3,4,empty] λ°°μ—΄ 생성
@khg0712
khg0712 / JS-array-type-Example3.js
Last active May 12, 2018 14:58
length ν”„λ‘œνΌν‹° μ‚¬μš© 예
var a = [1,2,3,4,5,6];//λ°°μ—΄ 생성
console.log(a.length);//6 좜λ ₯
a.length = 2;
console.log(a.length);//2 좜λ ₯
console.log(a);//[1,2] 좜λ ₯
@khg0712
khg0712 / JS-array-type-Example4.js
Created May 12, 2018 14:40
λ°°μ—΄μ—μ„œμ˜ delete μ—°μ‚°μž μ‚¬μš©
var a = [1,2,3,4];
delete a[1];
console.log(a);//[1,empty,3,4] 좜λ ₯
@khg0712
khg0712 / JS-array-type-Example5.js
Created May 12, 2018 14:55
splice λ©”μ„œλ“œ μ‚¬μš©λ°©λ²•
var a = [1,2,3,4,5];
a.splice(1,2);
console.log(a);//[1,4,5] 좜λ ₯
a.splice(3,0,'a','was',[1,4,5]);
console.log(a);//[1, 4, 5, "a", "was", Array(3)] 좜λ ₯
@khg0712
khg0712 / JS-function-type-Example1.js
Last active May 19, 2018 16:22
ν•¨μˆ˜ μ„ μ–Έλ¬Έ μ˜ˆμ‹œ
function add(a,b) {
return a + b;
}
@khg0712
khg0712 / JS-function-type-Example2.js
Created May 19, 2018 16:21
ν•¨μˆ˜ ν‘œν˜„μ‹ μ˜ˆμ‹œ
var add = function(a,b) {
return a + b;
}
@khg0712
khg0712 / JS-function-type-Example3.js
Created May 19, 2018 16:23
κΈ°λͺ… ν•¨μˆ˜ ν‘œν˜„μ‹ μ˜ˆμ‹œ
var add = function plus(a,b) {
return a + b;
}
@khg0712
khg0712 / JS-function-type-Example4.js
Created May 19, 2018 16:26
ν•¨μˆ˜ ν˜Έμ΄μŠ€νŒ… μ˜ˆμ‹œ
add(1,2);//3
function add(a,b) {
return a + b;
}
add(3,4);//7