본문 바로가기

JavaScript/JavaScript with Error15

[해결 방법] An identifier or keyword cannot immediately follow a numeric literal 👉 기본 환경 - Language: JavaScript - IDE: VS Code ⌨️ 코드 1 2 alert( 123456.toString(36) ); 🖨️오류 1 2 An identifier or keyword cannot immediately follow a numeric literal. 📡 원인 JavaScript에서 숫자 리터럴 다음에는 식별자나 키워드가 나타나서는 안됨 - JavaScript 파서가 숫자 리터럴과 그 다음에 오는 괄호 (를 잘못 해석 - JavaScript가 숫자 리터럴 다음에 바로 메소드를 호출하는 것을 이해하지 못하기 때문에 발생 📰 해결 방법 1 2 alert((123456).toString(36)); * 숫자 리터럴을 괄호로 감싸기 1 2 3 var num = 12345.. 2023. 10. 18.
[해결 방법] TypeError: Cannot create property '...' on string '...' 👉 기본 환경 - Language: JavaScript - IDE: VS Code ⌨️ 코드 1 2 3 4 5 let str = "Hello"; str.test = 5; alert(str.test); 🖨️오류 1 2 TypeError: Cannot create property 'test' on string 'Hello' 📡 원인 * 엄격 모드 - 래퍼 객체를 수정 시, 에러가 발생 * 비엄격 모드 - 래퍼 객체에 properties 'test' 추가 → 래퍼 객체 삭제 → properties 'test'를 찾을 수 없음 🚨 원시값은 추가 데이터를 저장할 수 없음 📰 해결 방법 1 2 3 4 5 let str = new String("Hello"); // 문자열을 객체로 변환 str.test = 5; al.. 2023. 10. 18.
[해결 방법] TypeError: props.forEach is not a function 🟨 기본 환경: IDE: VS code, Language: JavaScript 발생 Error JavaScript에서 다음 Source Code를 실행할 경우, 1 2 props.forEach(console.log(props.movieImg.length)); 🚨 다음과 같은 Error 발생 props.forEach is not a function TypeError: props.forEach is not a function 발생 원인 forEach()의 매개변수를 함수가 아닌 배열의 개별 인자를 전달 해결 방법 콜백 함수를 사용하여 배열의 각 요소를 반복 처리 1 2 3 4 props.forEach((data) => { console.log(data.movieImg.length); }); * callbac.. 2023. 6. 11.
[해결 방법] Error: Cannot find module 'C:\Users\user\Desktop\REACT\redux\productReducer.js' 🟨 기본 환경: IDE: VS code, Language: JavaScript 발생 Error CMD에서 node productSlice.js로 다음 Source Code를 실행할 경우, 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 const { createSlice } = require('@reduxjs/toolkit'); // createSlice: reducer 생성, 매개변수-객체 let initialState = { productList: [], selectedItem: null, }; // name: unique한 action name을 만드는데 쓰이는 prefix // initialState:.. 2023. 6. 6.
[해결 방법] SyntaxError: Cannot use import statement outside a module 🟨 기본 환경: IDE: VS code, Language: JavaScript 발생 Error CMD에서 node productSlice.js로 다음 Source Code를 실행할 경우, 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 import {createSlice} from '@reduxjs/toolkit'; // createSlice: reducer 생성, 매개변수-객체 let initialState = { productList: [], selectedItem: null, }; // name: unique한 action name을 만드는데 쓰이는 prefix // initialState: reduce.. 2023. 6. 6.
[해결 방법] TypeError: Cannot read properties of undefined (reading 'counter') 🟨 기본 환경: IDE: VS code, Language: JavaScript 발생 Error JavaScript에서 다음 Source Code를 실행할 경우, 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 const redux = require('redux'); const counterReducer = (state, action) => { return { counter: state.counter + 1 }; }; const store = redux.createStore(counterReducer); const counterSubscriber = () => { const latestState = store.getState(); console.log(latestState); }.. 2023. 6. 4.