**
const user = {
name:'Mike',
age:30
}
์์ ๊ฐ์ด user๋ผ๋ ๊ฐ์ฒด๊ฐ ์์ ๋,
๋ณต์ (๊น์ ๋ณต์ฌ)๋ฅผ ํ๊ธฐ ์ํด์
const cloneUser = user;
์์ ๊ฐ์ด ์์ฑํ๋ฉด ๊ธฐ๋ํ๋ ํจ๊ณผ(๊ฐ์ฒด๋ฅผ ๋ณต์ฌํด์ ๋ฃ๋๋ค)๋ฅผ ์ป์ ์ ์๋ค.(์์ธ: ์๋ ์บก์ฒ ์ฐธ๊ณ )
์๋ ์บก์ฒ๋ฅผ ์ฐธ๊ณ ํ๋ฉด ์ ์ ์๋ฏ์ด
cloneUser๋ ํ์ ๋ด๊ธด user๋ฅผ ๋ํผ๋ฐ์คํ๋ ๋ํผ๋ฐ์ค ๋ณ์๊ฐ ๋๋ค.(์์ ๋ณต์ฌ)(๊ฐ์ฒด๋ฅผ ์ฐธ์กฐํ๋ ๊ฐ์ด ๋ค์ด๊ฐ๋ค)
๋ฐ๋ผ์
cloneUser.age=44; ์์ผ๋ก cloneUser์ ํ๋กํผํฐ ๊ฐ์ ๋ฐ๊พธ์ด๋ฒ๋ฆฌ๋ฉด user.age์ ๋์ด๋ ๋๊ธฐํ๋์ด ๋ณ๊ฒฝ๋๋ ๊ฒ์ ์๋ ์์ ๋ฅผ ํตํด ํ์ธํ์๋ค.
let a = "age";
let user = {
name: "Jane",
[a]: 20,
[1 + 2]: 3,
["์๋
" + "ํ์ธ์"]: "hello",
sayHello: function () {
console.log(this.์๋
ํ์ธ์, " ", this.name);
},
};
console.log(user.name, "์ ๋์ด๋ ", user.age); //Jane ์ ๋์ด๋ 20
const cloneUser = user;
cloneUser.age = 44;
console.log(cloneUser.name, "์ ๋์ด๋ ", cloneUser.age); //Jane ์ ๋์ด๋ 44
console.log(user.name, "์ ๋์ด๋ ", user.age); //Jane ์ ๋์ด๋ 44
let a = "age";
let user = {
name: "Jane",
[a]: 20,
};
const newUser = Object.assign({}, user);
newUser.name = "Tom";
console.log(JSON.stringify(user)); //{"name":"Jane","age":20}
console.log(JSON.stringify(newUser)); //{"name":"Tom","age":20}
๋ณ์ a๋ ๊ฐ์ฒด user ์์์ computed property(๊ณ์ฐ๋ ํ๋กํผํฐ)๊ฐ ๋๋ค.
์ฌ์ง์ด ์ด๋ฐ ๊ฒ๋ ๋๋ค.
let a = "age";
let user = {
name: "Jane",
[a]: 20,
[1 + 2]: 3,
};
const newUser = Object.assign({}, user);
newUser.name = "Tom";
console.log(JSON.stringify(user)); //{"3":3,"name":"Jane","age":20}
console.log(JSON.stringify(newUser)); //{"3":3,"name":"Tom","age":20}
[1+2] ์ฒ๋ผ ์์ ๋ฃ๋ ๊ฒ๋ ๊ฐ๋ฅํ๋ค.
์ง๊ธ๊น์ง ๋ฐฐ์ด ๊ฒ๋ค๋ก ์ค์ต
let a = "age";
let user = {
name: "Jane",
[a]: 20,
[1 + 2]: 3,
["์๋
" + "ํ์ธ์"]: "hello",
sayHello: function () {
console.log(this.์๋
ํ์ธ์, " ", this.name);
},
};
const newUser = Object.assign({}, user);
newUser.name = "Tom";
console.log(JSON.stringify(user));
console.log(JSON.stringify(newUser));
user.sayHello();
let a = "age";
let user = {
name: "Jane",
[a]: 20,
[1 + 2]: 3,
["์๋
" + "ํ์ธ์"]: "hello",
sayHello: function () {
console.log(this.์๋
ํ์ธ์, " ", this.name);
},
};
console.log(user.name, "์ ๋์ด๋ ", user.age); //Jane ์ ๋์ด๋ 20
const cloneUser = user;
cloneUser.age = 44;
console.log(cloneUser.name, "์ ๋์ด๋ ", cloneUser.age); //Jane ์ ๋์ด๋ 44
console.log(user.name, "์ ๋์ด๋ ", user.age); //Jane ์ ๋์ด๋ 44
const newUser = Object.assign({}, user);
newUser.name = "Tom";
console.log(JSON.stringify(user)); //{"3":3,"name":"Jane","age":44,"์๋
ํ์ธ์":"hello"}
console.log(JSON.stringify(newUser)); //{"3":3,"name":"Tom","age":44,"์๋
ํ์ธ์":"hello"}
user.sayHello(); //hello Jane
const exUser = Object.assign({}, cloneUser);
console.log(JSON.stringify(exUser)); //{"3":3,"name":"Jane","age":44,"์๋
ํ์ธ์":"hello"}
exUser.name = "ํฉํ์";
console.log(JSON.stringify(cloneUser.name)); //"Jane"
console.log(JSON.stringify(exUser.name)); //"ํฉํ์"
let specialK = {
school: "SeoulUniv",
};
console.log(JSON.stringify(specialK)); //{"school":"SeoulUniv"}
const specialPerson = Object.assign(specialK, user);
console.log(JSON.stringify(specialK)); //{"3":3,"school":"SeoulUniv","name":"Jane","age":44,"์๋
ํ์ธ์":"hello"}
๊ทธ๋ฆฌํ์ฌ.. ์์ ๊ฐ์ด ์ค์ต์ ํด๋ณด์๋ค(๊ฒฐ๊ณผ๋ ์ฃผ์์!)
์ฒซ๋ฒ์งธ ์ธ์๊ฐ์ฒด์ ๋๋ฒ์งธ ์ธ์ ๊ฐ์ฒด ๊ธฐ์กด ํ๋กํผํฐ ํค๊ฐ ๊ฐ๋ค๋ฉด
๋๋ฒ์งธ ๊ฐ์ฒด ์ธ์(๊ฐ์ฒด) ์ ํค์ ๊ฐ์ผ๋ก ๋ฎ์ด์์์ง๋ค.
let info1 = {
menu: "๋๊ฐ์ ์",
};
let info2 = {
ํ์: "coffee",
};
let ํ์ = {
people: 9,
date: "2022/02/24",
};
Object.assign(ํ์, info1, info2);
console.log(JSON.stringify(ํ์)); //{"people":9,"date":"2022/02/24","menu":"๋๊ฐ","ํ์":"coffee"}
let info1 = {
menu: "๋๊ฐ์ ์",
};
let info2 = {
ํ์: "coffee",
};
let ํ์ = {
people: 9,
date: "2022/02/24",
};
Object.assign(ํ์, info1, info2);
console.log(JSON.stringify(ํ์)); //{"people":9,"date":"2022/02/24","menu":"๋๊ฐ","ํ์":"coffee"}
console.log(JSON.stringify(Object.keys(ํ์))); //["people","date","menu","ํ์"]
let info1 = {
menu: "๋๊ฐ์ ์",
};
let info2 = {
ํ์: "coffee",
};
let ํ์ = {
people: 9,
date: "2022/02/24",
};
Object.assign(ํ์, info1, info2);
console.log(JSON.stringify(ํ์)); //{"people":9,"date":"2022/02/24","menu":"๋๊ฐ","ํ์":"coffee"}
console.log(JSON.stringify(Object.keys(ํ์))); //["people","date","menu","ํ์"]
console.log(JSON.stringify(Object.values(ํ์))); //[9,"2022/02/24","๋๊ฐ์ ์","coffee"]
let info1 = {
menu: "๋๊ฐ์ ์",
};
let info2 = {
ํ์: "coffee",
};
let ํ์ = {
people: 9,
date: "2022/02/24",
};
Object.assign(ํ์, info1, info2);
console.log(JSON.stringify(ํ์)); //{"people":9,"date":"2022/02/24","menu":"๋๊ฐ","ํ์":"coffee"}
console.log(JSON.stringify(Object.keys(ํ์))); //["people","date","menu","ํ์"]
console.log(JSON.stringify(Object.values(ํ์))); //[9,"2022/02/24","๋๊ฐ์ ์","coffee"]
console.log(JSON.stringify(Object.entries(ํ์))); //[["people",9],["date","2022/02/24"],["menu","๋๊ฐ์ ์"],["ํ์","coffee"]]
const array = [
["name", "Hong GilDong"],
["gender", "man"],
["job", "programmer"],
];
const employee = Object.fromEntries(array);
console.log(JSON.stringify(employee));//{"name":"Hong GilDong","gender":"man","job":"programmer"}
function makeObj(key, val) {
return { [key]: val };
}
const staff = makeObj("gender", "female");
const information1 = {
name: "yumi",
};
const information2 = {
age: 22,
};
console.log(
JSON.stringify(Object.assign(staff, information1, information2))
); //{"gender":"female","name":"yumi","age":22}
<๋นํ๊ดด์ ์ฒ๋ฆฌ, ํ๊ดด์ฒ ์ฒ๋ฆฌ>
์ด๊ธฐ ์๋ฐ์คํฌ๋ฆฝํธ๊ฐ ํ๋๋ ์์ ์๋ ํ๋์จ์ด ๋ฐ์ ์ด ๋ฏธ๋ฏธํ๊ธฐ ๋๋ฌธ์ ๋ฉ๋ชจ๋ฆฌ ๊ด๋ฆฌ ์ฐจ์์์ ๋ฉ์๋๋ค์ ํน์ง์ด 'ํ๊ดด์ ์ฒ๋ฆฌ'์๋ค.
ํ์ง๋ง ๊ทผ๋ ์์๋ ๋ฉ๋ชจ๋ฆฌ๊ฐ ๋์ณ๋๋ฉฐ, ํ๋ก๊ทธ๋จ์ ๋ณตํฉ์๋ฃํ๋ค์ด ์๋ณธ์ ์ ์งํ๊ณ ์์ด์ผ ์์ ํ ๊ฒฝ์ฐ๊ฐ ๋ง์ผ๋ฏ๋ก 2010๋ ์ดํ์ ์๋ฐ์คํฌ๋ฆฝ์ ์ถ๊ฐ๋ ๋ฉ์๋๋ค์ '๋นํ๊ดด์ ์ฒ๋ฆฌ'๋ฅผ ์ง์ํ๋ค.
...์์ฝ๊ฒ๋ ํจ์์ ๋ฉ์๋ ์ด๋ฆ๋ง ๋ณด๊ณ ์ฒ๋ฆฌ์ ํน์ง์ด ํ๊ดด์ ์ธ์ง ๋นํ๊ดด์ ์ธ์ง ์ ์ ์๋ค.
์ด๊ธฐ๋ถํฐ ์์๋ push()๋ ํ๊ดด์ ์ฒ๋ฆฌ์ด๋ค.๐ฅฒ
<const์ ์ปจ์ ์ ์คํ์์ญ(๊ฐํ์)์์๋ง ์ ์ฉ๋๋ค>
const choiceNum = 7;
choiceNum = 777;//Uncaught TypeError: Assignment to constant variable
const numbers = [1, 2, 3];
numbers.push(4);
console.log(JSON.stringify(numbers)); //[1,2,3,4]
const๋ก ์ ์ธํ ์คํ์ ์ ์ฉ๋ ๊ฐ์๋ฃํ์ ๋ณ๊ฒฝ ์๋๊ฐ ์ฐจ๋จ๋๋ค.
๋ฐฐ์ด์ const๋ก ์ ์ธํ๋ค๋ฉด ๋ณ์๋ช ์ ํ์ ์ ์ธ๋ ๋ฐฐ์ด์ ์ฃผ์์ผ ๋ฟ์ด๊ณ ์ค์ ๊ฐ์ ํ์ ์๋ค.
๋ฐฐ์ด์ ์ด๋ฆ์ ๋ฐฐ์ด์ ์์ ์ฃผ์์ด๋ค!์ ๊ฐ๋ ์ ๋ ์ฌ๋ฆฌ๋ฉด ์ฝ๋ค.
//main ์ธ์ด๊ฐ C#์ด๊ธฐ ๋๋ฌธ์, ์ ์ ๋น๊ตํ๋ ค๊ณ c# ๊ธฐ์ค ์์ง์ ๋ธ๋ก๊ทธ๊ธ๋ค์ ์ฐธ๊ณ ํด์ ํ์ธ
https://glassnabi.tistory.com/8
๋ฐฐ์ด์ ์ด๋ฆ์ ๋ฐฐ์ด์ ์์ ์ฃผ์์ด๋ค!
1. ์ด ๊ธ์ ์ฝ๊ธฐ ์ ์ ๋ด์ผ ํ ๋ด์ฉ ์ด ๊ธ์ ์๋์ ๋งํฌํ ๊ธ์ ์ฐ๊ฒฐ๋๋ ๋ด์ฉ์ ๋๋ค. ๋ฐ๋ผ์ ์๋์ ๊ธ์...
blog.naver.com
https://www.sysnet.pe.kr/2/0/12624
.NET Framework: 1055. C# - struct/class๊ฐ ์คํ/ํ์ ํ ๋น๋๋ ์ฌ๋ก ์ ๋ฆฌ
.NET Framework: 1055. C# - struct/class๊ฐ ์คํ/ํ์ ํ ๋น๋๋ ์ฌ๋ก ์ ๋ฆฌ [๋งํฌ ๋ณต์ฌ], [๋งํฌ+์ ๋ชฉ ๋ณต์ฌ] ์กฐํ: 1848 ๊ธ์ด ์ฌ๋ ์ ์ฑํ (techsharer at outlook.com) ํํ์ด์ง ์ฒจ๋ถ ํ์ผ ๋ถ๋ชจ๊ธ ๋ณด์ด๊ธฐ/๊ฐ์ถ๊ธฐ C# - struc
www.sysnet.pe.kr
๊ฐํ์ | ์ฐธ์กฐํ์ | |
์ ์ฅ์์น | ์คํ | ํ ๋ฉ๋ชจ๋ฆฌ |
ํ ๋น๋ ๊ณณ์ ์ ์ฅ๋๋ ๋ฐ์ดํฐ | ์ ๋ ฅํ ๋ฐ์ดํฐ | ๋ฐ์ดํฐ๊ฐ ์์นํ๊ณณ์ ์ฐธ์กฐ |
ํน์ง | ํด๋น ๋ฉ์๋ ์คํ์ด ์ข
๋ฃ๋๋ฉด ์ฌ๋ผ์ง int a = 1; int b = a; ์์ a,b์ ๊ฐ์ค ์ด๋ ํ๋์ ๊ฐ์ ์์ ํด๋ ๋ค๋ฅธ์ชฝ์๋ ์ํฅ์ ๋ผ์น์ง ์๋๋ค |
GC์ ์ํด ์ ๋ฆฌ๋จ. ์๋ก ๋ค๋ฅธ ๋ ๋ณ์๊ฐ ๊ฐ์ ๋ฐ์ดํฐ๋ฅผ ์ฐธ์กฐํ๋ค๋ฉด ํ๊ฐ์ ๋ณ์๊ฐ์ ๋ณ๊ฒฝํ๋ฉด ๋ค๋ฅธ ๋ณ์๋ ์ํฅ์ ๋ฐ๋๋ค. |
๋ณํ | ๊ฐํ์ -> ์ฐธ์กฐํ์ Boxing |
์ฐธ์กฐํ์ -> ๊ฐํ์ UnBoxing |
๋ณต์ฌ | ์์๋ณต์ฌ | ๊น์๋ณต์ฌ |
์ | ๊ตฌ์กฐ์ฒด(์ซ์(๋ถ๋์์์ ,decimal),bool, ์ฌ์ฉ์์ ์๊ตฌ์กฐ์ฒด), ์ด๊ฑฐํ: bool, char, byte, decimal, double, enum, float, int long, short, sbyte, struct, uint, ulong, ushort | class, interface, delegate, object, string |
C#์๋ ๊ฐ ํ์๊ณผ ์ฐธ์กฐ ํ์์ด๋ผ๋ ๋ ๊ฐ์ง ๋ฐ์ดํฐ ํ์์ด ์์ต๋๋ค. ์์ฉ ํ๋ก๊ทธ๋จ์ ์ฑ๋ฅ์ด ์ค์ํ๊ฑฐ๋ C#์ ๋ฐ์ดํฐ ๋ฐ ๋ฉ๋ชจ๋ฆฌ ๊ด๋ฆฌ ๋ฐฉ์์ ๊ด์ฌ์ด ์๋ ๊ฒฝ์ฐ์๋ ๋ ํ์์ ์ฐจ์ด์ ์ ์์์ผ ํฉ๋๋ค. ์ฐจ์ด์ ์ ์ด๋ค ํ์์ด ๋ณต์ฌ๋๋ ๋ฐฉ์์ ๋ฐ๋ผ ๋๋๊ฒ ๋๋ค.
๊ฐํ์์ ๋ฐ์ดํฐ๋ ํญ์ ๊ฐ์ผ๋ก ๋ณต์ฌ๋์ง๋ง, ์ฐธ์กฐํ์ ๋ฐ์ดํฐ๋ ํญ์ ์ฐธ์กฐ๋ก ๋ณต์ฌ๋๋ค.
๊ฐ ํ์ (Value Type) |
๊ฐ ํ์์ ๊ธฐ๋ฐ์ผ๋ก ํ ๋ณ์์๋ ๊ฐ์ด ์ง์ ํฌํจ๋ฉ๋๋ค. ๊ฐ ํ์ ๋ณ์ ํ๋๋ฅผ ๋ค๋ฅธ ๋ณ์์ ๋์
ํ๋ฉด ๋ณ์์ ํฌํจ๋ ๊ฐ์ด ๋ณต์ฌ๋ฉ๋๋ค. ๋ชจ๋ ๊ฐ ํ์์ ์์์ ์ผ๋ก System.ValueType์์ ํ์. |
๊ฐ ํ์์ ๊ธฐ๋ณธ์ ์ผ๋ก ๊ตฌ์กฐ์ฒด์ ์ด๊ฑฐํ์ผ๋ก ๊ตฌ๋ถํ ์ ์์ต๋๋ค.
๋ ์ฌ๊ธฐ์ ๊ตฌ์กฐ์ฒด๋ ์ซ์(์ ์ , ๋ถ๋ ์์์ , decimal ) , bool , ์ฌ์ฉ์ ์ ์ ๊ตฌ์กฐ์ฒด๋ก ๊ตฌ๋ถ ํ ์ ์์ต๋๋ค.
๊ฐ ํ์์ ์คํ์ ํ ๋น๋ ๋ฉ๋ชจ๋ฆฌ์ ๋ด์ฉ์ ์ ์ฅํฉ๋๋ค.
์๋ ๊ฒฝ์ฐ์๋ ์คํ์ด๋ผ๋ ๋ฉ๋ชจ๋ฆฌ ์์ญ์ ๊ฐ 7์ด ์ ์ฅ๋ฉ๋๋ค.
๋ณ์๊ฐ ์ ์๋ ๋ฉ์๋์ ์คํ์ด ์ข ๋ฃ๋์ด ๋ณ์๊ฐ ๋ฒ์๋ฅผ ๋ฒ์ด๋๋ฉด ๊ฐ์ด ์คํ์์ ์ญ์ ๋ฉ๋๋ค.
์ฐธ์กฐ ํ์ ( Reference Type) |
์ฐธ์กฐ ํ์ ๋ณ์์ ๊ฒฝ์ฐ ๊ฐ์ฒด ์์ฒด๊ฐ ์๋๋ผ ๊ฐ์ฒด์ ๋ํ ์ฐธ์กฐ๊ฐ ๋ณต์ฌ๋ฉ๋๋ค. ์ฐธ์กฐ ํ์์์๋ ๋ ๊ฐ์ง ๋ณ์๊ฐ ๊ฐ์ ๊ฐ์ฒด๋ฅผ ์ฐธ์กฐํ ์ ์์ผ๋ฏ๋ก ํ ๋ณ์์ ๋ํ ์์ ์ด ๋ค๋ฅธ ๋ณ์์์ ์ฐธ์กฐํ๋ ๊ฐ์ฒด์ ์ํฅ์ ๋ฏธ์น ์ ์์ต๋๋ค. ๊ฐ ํ์์์๋ ๊ฐ ๋ณ์์ ๋ฐ์ดํฐ์ ์์ฒด ์ฌ๋ณธ์ด ๋ค์ด ์์ผ๋ฉฐ ํ ๋ณ์์ ์์ ์ด ๋ค๋ฅธ ๋ณ์์ ์ํฅ์ ๋ฏธ์น ์ ์์ต๋๋ค |
์ฐธ์กฐ ํ์์ผ๋ก๋ ํด๋์ค , ์ธํฐํ์ด์ค , ๋ธ๋ฆฌ๊ฒ์ดํธ๊ฐ ์์ผ๋ฉฐ,
๊ธฐ๋ณธ์ ์ผ๋ก ๋ค์ด๋๋ฏน , ์ค๋ธ์ ํธ , ์คํธ๋ง์ ๊ธฐ๋ณธ ์ฐธ์กฐ ํ์๋ ์ ๊ณตํ๊ณ ์์ต๋๋ค.
์คํ์ ์ฌ์ฉํ๋ฉด ํจ์จ์ ์ด์ง๋ง ๊ฐ ํ์์ ์๋ช ์ด ์ ํ๋๋ฏ๋ก ์๋ก ๋ค๋ฅธ ํด๋์ค ๊ฐ์ ๋ฐ์ดํฐ๋ฅผ ๊ณต์ ํ๋ ๋ฐ๋ ์ ํฉํ์ง ์๋ค.
๋ฐ๋๋ก ํด๋์ค ๋๋ ๋ฐฐ์ด์ ์ธ์คํด์ค์ ๊ฐ์ ์ฐธ์กฐ ํ์์ ํ์ด๋ผ๋ ๋ค๋ฅธ ๋ฉ๋ชจ๋ฆฌ ์์ญ์ ํ ๋น๋๋ค.
์๋ ๋ฐฐ์ด์ ๊ตฌ์ฑํ๋ 10๊ฐ์ ์ ์์ ํ์ํ ๊ณต๊ฐ์ด ํ์ ํ ๋น๋ฉ๋๋ค.
1
|
int[] numbers = new int[10];
|
cs |
์ด ๋ฉ๋ชจ๋ฆฌ๋ ๋ฉ์๋๊ฐ ์ข ๋ฃ๋์ด๋ ํ์ ๋ฐํ๋์ง ์์ผ๋ฉฐ, C#์ ๊ฐ๋น์ง ์์ง ์์คํ ์์ ์ด ๋ฉ๋ชจ๋ฆฌ๊ฐ ๋ ์ด์ ํ์ํ์ง ์๋ค๊ณ ํ๋จํ ๋์๋ง ํ์๋๋ค. ์ฐธ์กฐ ํ์์ ์ ์ธํ๋ฉด ์ค๋ฒํค๋๊ฐ ์ปค์ง์ง๋ง ์ฐธ์กฐ ํ์์ ๋ค๋ฅธ ํด๋์ค์์ ์ก์ธ์คํ ์ ์๋ค๋ ์ฅ์ ์ด ์๋ค.
๋ฐ์ดํฐ๋ฅผ ๊ฐ ํ์ ๋งค๊ฐ ๋ณ์๋ก ๋ฉ์๋์ ์ ๋ฌํ๋ฉด ์คํ์ ๊ฐ ๋งค๊ฐ ๋ณ์์ ๋ณต์ฌ๋ณธ์ด ๋ง๋ค์ด์ง๋ค. ๋ฐ๋ผ์ ํด๋น ๋งค๊ฐ ๋ณ์๊ฐ ๋ง์ ์์๊ฐ ์๋ ์ฌ์ฉ์ ์ ์ ๊ตฌ์กฐ์ฒด์ ๊ฐ์ ํฐ ๋ฐ์ดํฐ ํ์์ด๊ฑฐ๋ ๋ฉ์๋๊ฐ ์ฌ๋ฌ ๋ฒ ์คํ๋๋ ๊ฒฝ์ฐ ์ฑ๋ฅ์ ์ํฅ์ ์ค ์ ์๋ค.
์ถ์ฒ: https://cho22.tistory.com/56 [๊ฒ์ ๊ฐ๋ฐ์]
https://parksh86.tistory.com/114
const choiceNum = 7;
choiceNum = 777; //Uncaught TypeError: Assignment to constant variable
const numbers = [1, 2, 3];
numbers.push(4);
console.log(JSON.stringify(numbers)); //[1,2,3,4]
const numbers = [4, 5, 6];//Uncaught SyntaxError: Identifier 'numbers' has already been declared
const๋ก ์ด๊ธฐํํ ๋ฐฐ์ด ๊ฐ์ฒด์ ์์ ๋ค๋ฅธ ๋ฐฐ์ด ๊ฐ์ฒด๋ฅผ ๋ฎ์ด์์ฐ๋ ํ์๋ ๋งํ์ง๋ง,
ํ์ ์๋ ๊ฐ์ฒด ๋ด์ฉ์ ์ง์ง๊ณ ๋ณถ๊ณ ์๋ฅด๊ณ ํ๋ ํจ์๋ค์ const๋ก ๋ฐํ์์ด๋ ํ๊ดด์ ์ฒ๋ฆฌ๊ฐ ์ ์ด๋ฃจ์ด์ง๋ค.
<๋ฐฐ์ด ๋ด๋ถ์์ ํน์ ๊ฐ์ ๊ฐ์ง ์์ ๋ชจ๋ ์ ๊ฑฐํ๊ธฐ>
const ์์กด์ = ["์์ง", "๊ฒฝ์", "zombie", "ํ๋ฏธ", "zombie"];
const ์ธ๋ฅ = ์์กด์.filter((item) => item !== "zombie");
console.log(JSON.stringify(์์กด์));//["์์ง","๊ฒฝ์","zombie","ํ๋ฏธ","zombie"]
console.log(JSON.stringify(์ธ๋ฅ)); //["์์ง","๊ฒฝ์","ํ๋ฏธ"]
<์ต์ข ์ ๋ฆฌ>
const dieUser = {
blood: "A",
};
const kei = dieUser;
console.log(JSON.stringify(kei));//{"blood":"A"}
const sumi = { blood: "B" };
'Javascript > Javascript' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[๊ธฐ์ด ์๋ฐ์คํฌ๋ฆฝํธ] ๋๋ฆผ์ฝ๋ฉ by ์๋ฆฌ๋ ์๋ฐ์คํฌ๋ฆฝํธ ๊ธฐ์ด ๊ฐ์ (ES5+) ์๋ฆฌ์ฆ ์ ์ฃผํ ๊ธฐ๋ก (0) | 2022.03.25 |
---|---|
[์ค๊ธ ์๋ฐ์คํฌ๋ฆฝํธ] ์ฌ๋ณผ (0) | 2022.03.24 |
[์๋ฐ์คํฌ๋ฆฝํธ] ๋์ ์์ฑ (0) | 2022.03.23 |
ํธ๋ผํ ์นด๋ ๋ค์ง๊ธฐ ์์ (0) | 2022.03.23 |
[์๋ฐ ์คํฌ๋ฆฝํธ] ์ฆ์์คํํจ์... ๊ทธ๋ฆฌ๊ณ ํด๋ก์ (0) | 2022.03.21 |