๐ŸŸจ JavaScript/๊ฐœ๋…

    [๋“œ๋ฆผ์ฝ”๋”ฉ] ์ฝœ๋ฐฑํ•จ์ˆ˜ (1) : ์ฝœ๋ฐฑ์ง€์˜ฅ ์˜ˆ์‹œ

    ์ฝœ๋ฐฑ์ง€์˜ฅ // ๊ธฐ๋ณธ์„ธํŒ… class UserStorage { loginUser(id, password, onSuccess, onError) { setTimeout(() => { if ( (id === 'master' && password === 'master00') || (id === 'submaster' && password === 'submaster00') ) { onSuccess(id); } else { onError(new Error('not found')); } }, 2000); } getRoles(user, onSucces, onError) { setTimeout(() => { if (user === 'master') { onSuccess({name: 'Master', role : 'admin'..

    [mdn, ๋“œ๋ฆผ์ฝ”๋”ฉ, ์ฝ”๋”ฉ์• ํ”Œ] ์ฝœ๋ฐฑํ•จ์ˆ˜ (1) : ๋™๊ธฐ์™€ ๋น„๋™๊ธฐ ๊ฐœ๋…

    ์ฝœ๋ฐฑํ•จ์ˆ˜ ์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ๋Š” ๋™๊ธฐ์ (synchronous) ์–ธ์–ด์ด๋‹ค. ์ด ๋ง์€ ์ฝ”๋“œ๋ฅผ ์ž‘์„ฑํ•œ ์ˆœ์„œ์— ๋งž์ถฐ ๋™๊ธฐ์ ์œผ๋กœ ์‹คํ–‰๋œ๋‹ค๋Š” ๋ง์ด๋‹ค. ์•„๋ž˜๋Š” ๋น„๋™๊ธฐ์ ์œผ๋กœ ์‹คํ–‰๋˜๋Š” ํ•จ์ˆ˜์ด๋‹ค. console.log('1'); setTimeout(() => console.log('2'), 1000); console.log('3'); //1 //3 //2 Synchronous callback function printImmediately(print) { print(); } printImmediately(() => console.log('hello')); Asynchronous callback function printWithdelay(print, timeout) { setTimeout(print, timeout); } printW..

    [๋“œ๋ฆผ์ฝ”๋”ฉ] JSON to Object (parse)

    JSON to Object parse(json) const coder = { name: 'Noran', language: 'Javascript', height: null, birthDate: new Date(), sayhi: () => { console.log(`Hello, I'm ${name}!`); }, }; json = JSON.stringify(coder); const obj = JSON.parse(json); console.log(obj); //{name: 'Noran', language: 'Javascript', height: null, birthDate: '2022-07-12T03:03:18.870Z'}birthDate: "2022-07-12T03:03:18.870Z"height: nulll..

    [๋“œ๋ฆผ์ฝ”๋”ฉ] Object to JSON (stringify)

    Object to JSON stringify(obj) stringify๋Š” ๋ฐ์ดํ„ฐ๋ฅผ stringํƒ€์ž…์œผ๋กœ ๋ณ€ํ™˜ํ•œ๋‹ค. let json = JSON.stringify(true); console.log(json); //"true" let json = JSON.stringify(['Noran','Paran']); console.log(json); //["Noran","Paran"] ํ•œ๊ฐœ์˜ single quote๊ฐ€ ์•„๋‹Œ double quote๋กœ ๋ฐ”๋€ ๊ฒƒ์„ ๋ณผ ์ˆ˜ ์žˆ๋‹ค. ์ด๊ฒƒ์ด JSON์˜ ๊ทœ๊ฒฉ์‚ฌํ•ญ์ด๋‹ค. ๋˜ํ•œ ์•„๋ž˜์ฒ˜๋Ÿผ ํ•จ์ˆ˜๋‚˜ javascript์—๋งŒ ์ž์ฒด์ ์œผ๋กœ ๋“ค์–ด์žˆ๋Š” ๋ฐ์ดํ„ฐ๋„ JSON์— ํฌํ•จ๋˜์ง€ ์•Š๋Š”๋‹ค. const coder = { name: 'Noran', language: 'Javascript', height: nu..

    [๋“œ๋ฆผ์ฝ”๋”ฉ] JSON์ด๋ž€?

    JSON JavaScript Object Notation JSON์˜ Object ๋˜ํ•œ javascript์ฒ˜๋Ÿผ {key: value}๋กœ ์ด๋ฃจ์–ด์ ธ ์žˆ๋‹ค. ๋ฐ์ดํ„ฐ๋ฅผ ์ฃผ๊ณ ๋ฐ›์„ ๋•Œ ์“ธ ์ˆ˜ ์žˆ๋Š” ๊ฐ€์žฅ ๊ฐ„๋‹จํ•œ format์ด๋‹ค. C,C++,C#,JAVA,Python,PHP ๋“ฑ์˜ ๊ฑฐ์˜ ๋Œ€๋ถ€๋ถ„์˜ ์–ธ์–ด๋“ค์€ ๋ชจ๋‘ JSON์œผ๋กœ serialization(์ง๋ ฌํ™”)๋œ object๋ฅผ ๋‹ค์‹œ ๊ทธ ์–ธ์–ด์— ๋งž๊ฒŒ object๋กœ ๋ณ€ํ™˜ ๋ฐ ๋‹ค์‹œ JSON์œผ๋กœ serialization(์ง๋ ฌํ™”)ํ•  ์ˆ˜ ์žˆ๋‹ค. ์ถœ์ฒ˜ : ๋“œ๋ฆผ์ฝ”๋”ฉ https://www.youtube.com/@dream-coding / MDN https://developer.mozilla.org/ko

    [๋“œ๋ฆผ์ฝ”๋”ฉ] ์œ ์šฉํ•œ ๋ฐฐ์—ด(array) api (3) : reduce, reduceRight, sort, api ๋‹ค์ค‘์œผ๋กœ ์“ฐ๊ธฐ

    class Coder { constructor(name, age, enrolled, score) { this.name = name; this.age = age; this.enrolled = enrolled; this.score = score; } } const coders = [ new Coder('A', 29, true, 45), new Coder('B', 28, false, 80), new Coder('C', 30, true, 90), new Coder('D', 40, false, 66), new Coder('E', 18, true, 88), ] reduce ๋ฐฐ์—ด์˜ ๊ฐ ๋ฐ์ดํ„ฐ์— ์ฃผ์–ด์ง„ ๋ฆฌ๋“€์„œ(reducer)ํ•จ์ˆ˜๋ฅผ ์‹คํ–‰ํ•˜๊ณ , ํ•˜๋‚˜์˜ ๊ฒฐ๊ณผ๊ฐ’์„ ๋ฐ˜ํ™˜ํ•œ๋‹ค. ๋ฆฌ๋“€์„œ ์ฝœ๋ฐฑํ•จ์ˆ˜๋Š” ๋„ค ๊ฐœ์˜ ์ธ์ž๋ฅผ ๊ฐ€์ง„๋‹ค. ๋ˆ„์‚ฐ๊ธฐ(..