let's get IT with DAVINA ๐Ÿ’ป

[Error] octal literals are not allowed in strict mode ๋ณธ๋ฌธ

DEV_IN/๋ฌธ์ œํ’€์ด

[Error] octal literals are not allowed in strict mode

๋‹ค๋นˆ์น˜์ฝ”๋“œ๐Ÿ’Ž 2023. 3. 9. 19:07
์•Œ๊ณ ๋ฆฌ์ฆ˜ ๋ฌธ์ œ ํ’€์ด ์ค‘, ๋ฌธ์ œ ์ž์ฒด๋Š” ์–ด๋ ต์ง€ ์•Š์•˜์ง€๋งŒ ๊ณ„์† ํ…Œ์ŠคํŠธ ์ผ€์ด์Šค๊ฐ€ console์— ์ž…๋ ฅํ–ˆ์„๋•Œ์™€ ๋‹ค๋ฅธ output์„ returnํ•˜๊ธธ๋ž˜ ํ•œ์ฐธ์„ ํ•ด๋งธ๋‹ค..
ํ•œ debugging tool์„ ์ด์šฉํ•ด์„œ ํ•œ๋‹จ๊ณ„์”ฉ ๋‚ด ์ฝ”๋“œ๋ฅผ ๋œฏ์–ด๋ณด๊ณ ์ž ํ–ˆ๋”๋‹ˆ
"octal literals are not allowed in strict mode" ๋ž€ ์—๋Ÿฌ์™€ ๋งˆ์ฃผ์ณค๋‹ค.. ์ƒ์ „ ์ฒ˜์Œ๋ณด๋Š” ์—๋Ÿฌ๋ผ ์ž‘์„ฑํ•œ๋‹ค ๋ธ”๋กœ๊ทธ!
๐Ÿšซ octal literals are not allowed in strict mode
  • 010๊ณผ ๊ฐ™์€ ๋ฆฌํ„ฐ๋Ÿด์„ ์‚ฌ์šฉํ•  ๋•Œ ๋งŒ๋‚  ์ˆ˜ ์žˆ๋Š” ์˜ค๋ฅ˜๋ผ๊ณ  ํ•œ๋‹ค.
  • es6 ๋ชจ๋“ˆ์„ ์ •์˜ํ•˜๋Š” ๊ฒฝ์šฐ ๋ชจ๋“ˆ์˜ ์Šค์ฝ”ํ”„๋Š” ์ž๋™์œผ๋กœ strict ๋ชจ๋“œ๊ฐ€ ๋˜๋Š”๋ฐ ํŠน๋ณ„ํžˆ strict ๋ชจ๋“œ์—์„œ๋Š” ์ด์ „์˜ 010 ๊ณผ ๊ฐ™์€ 8์ง„์ˆ˜ ํ‘œ๊ธฐ๋ฒ•์„ ์• ๋งคํ•œ ํ‘œ๊ธฐ๋ฒ•์œผ๋กœ ๊ทœ์ •ํ•ด ์‚ฌ์šฉํ•˜์ง€ ๋ชปํ•˜๊ฒŒ ํ–ˆ๋‹ค.
  • ๊ทธ๋Ÿฌ๋ฏ€๋กœ strict ๋ชจ๋“œ์—์„œ eval(‘010’) ๊ณผ ๊ฐ™์€ ํ‘œ๊ธฐ๋ฒ•์€ ์‚ฌ์šฉ์ด ๋ถˆ๊ฐ€(eval ์—์„œ '010' ์„ 010์œผ๋กœ ํ‰๊ฐ€ํ•˜๊ธฐ ๋•Œ๋ฌธ์—)
  • ์•ฝ๊ฐ„์˜ ๊ผผ์ˆ˜๋ฅผ ์‚ฌ์šฉํ•ด eval(‘000’*1) ์™€ ๊ฐ™์ด ํ•˜๋ฉด ์˜ค๋ฅ˜์—†์ด 10์ง„์ˆ˜ ๋ณ€ํ™˜์ด ๋จ

๐Ÿ’ก ๋‚ด๊ฐ€ ๋งŒ๋‚œ problem

  • 100,000์œผ๋กœ ์จ์ค˜์„œ error ๋ฐœ์ƒ → 100000์œผ๋กœ changeํ•ด์„œ ํ•ด๊ฒฐ..
function solution(price) {
    if(price<100000){ //๐Ÿšซ100,000
        return price;
    } else if(100000<=price && price<300000){ //๐Ÿšซ100,000 && //๐Ÿšซ300,000
        return Math.floor(price*0.95);
    } else if (300000<=price && price<500000){
        return Math.floor(price*0.9);
    } else if(500000<=price) {
        return Math.floor(price*0.8);
    }
}
 

 

Comments