-
Notifications
You must be signed in to change notification settings - Fork 0
/
basic.js
69 lines (57 loc) · 1.18 KB
/
basic.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
//객체야 안녕?
const user ={
name : "John",
surname : "Smith"
}
user.name = "Pete";
delete user.name;
//객체가 비어있는지 확인하기
let schedule ={};
function isEmpty(obj){
if(obj.key === undefined){
return true;
}
else{
return false;
}
}
// function isEmpty(obj) {
// for (let key in obj) {
// // if the loop has started, there is a property
// return false;
// }
// return true;
// }
console.log(isEmpty(schedule));
//변하지 않는 객체?
const person ={
name : "John"
};
person.name = 'Pete';
//변할 수 있다. 그 안에 있는 내용도 const가 되는 건 아님
//프로퍼티 합계 구하기
let salaries ={
John :100,
Ann: 160,
Pete: 130
}
const sum = salaries.John + salaries.Ann + salaries.Pete;
let sum2 = 0;
for (let key in salaries){
sum2 += salaries[key];
}
//프로퍼티 값 두배로 불리기
let menu = {
width: 200,
height: 300,
title: "My menu"
};
function mulitplyNumeric(obj){
for(let key in obj){
if(typeof(obj[key]===Number)){
obj[key] *= 2
}
return obj
}
}
console.log(mulitplyNumeric(menu));