-
[React] Uncaught TypeError: Assignment to constant variable 해결ETC/트러블슈팅 2022. 7. 20. 16:50
에러 발생한 코드
const imgPath=""; if(content.imageKeys != undefined) { imgPath="안녕하세요"; }
해당 에러는 여러 프레임워크에서 볼 수 있다
에러 원인은 const 로 선언한 변수에 새로운 값을 할당해서이다.
const 는 재할당을 허용하지 않는다
해결
새로운 값을 할당하고싶으면 const 대신 let을 써주면 된다
let imgPath=""; if(content.imageKeys != undefined) { imgPath="안녕하세요"; }
그럼 변수 imgPath 의 값이 '안녕하세요' 로 재할당된다
'ETC > 트러블슈팅' 카테고리의 다른 글
[React] Warning: react-modal: App element is not defined. 해결 (0) 2023.01.19 [React] TypeError: window.location.href is not a function 해결 (0) 2022.07.19 [React] POST 415 (Unsupported Media Type) error 해결 (0) 2022.07.17 [React] TypeError: Cannot read properties of undefined (reading 'substring') 해결 (0) 2022.07.13