Member-only story
Javascript Most frequent Errors — Guide — Reason and Options to fix
Debugging is an art and it is very important that we use right tools, reading errors is big assest which gives a clear information on what went wrong.
not defined
console.log(tax);
tax is not defined
It is a reference error and whenever we use a variable, it should be either declared or defined in the same file or imported from a file where it is declared or defined and exported
const tax = 10
— Option 1
let tax
— Option 2
import {tax} from 'somefile'
— Option 3
Cannot read properties of undefined (reading ‘something’)
let user;
console.log(user.name)
Value of the user is undefined, we try to access properties of an undefined variable, we get this.
We can either user ?
or we need to define the variable as object
console.log(user?.name)
— Option 1
let user={}
— Option 2
let user={name:'Vinodh'}
— Option 3