Skip to main content

COMMON ERROR IN JS

COMMON ERROR IN JS

TypeError: Cannot read property ‘length’

     This kind of error occurs when we are reading length property for       an undefined variable.

FIX    

To fix this we need to check whether the data type assigned to that variable have the length property

Uncaught TypeError: Cannot set property

 This kind of error occur when we are  trying to set a property for some data type which doesn’t have Property .For Example data type undefined doesn’t have any property

FIX    

To fix this we need to check whether the data type assigned to that variable have any property or not

Uncaught TypeError: Cannot read property

This kind of error occur when we are trying to access the defined variables/function/data

FIX    

To fix this we need to check whether the data has some value and it not equal to undefined

TypeError: ‘undefined’ is not an object (evaluating

    This is an error that occurs in Safari when you read a property or call a method on an undefined object. You can test this very easily in the Safari Developer Console. This is essentially the same as the above error for Chrome, but Safari uses a different error message.

FIX    

To fix this we need to check whether the data has some value and it not equal to undefined

 

TypeError: null is not an object (evaluating

        This is an error that occurs in Safari when you read a property or call a method on a null object.

FIX

        To fix this error we need to add an event listener that will notify           us when the page is ready. Once the addEventListener is fired, the init() method can make use of the DOM elements

 (unknown): Script error

        The Script error occurs when an uncaught JavaScript error crosses domain boundaries in violation of the cross-origin policy.

FIX    

        Setting the Access-Control-Allow-Origin header to * signifies that the resource can be accessed properly from any domain

TypeError: Object doesn’t support property

        This is an error that occurs in IE when you call an undefined method.

FIX    

        To fix this error check whether this.function is not undefined

TypeError: ‘undefined’ is not a function

This is an error that occurs in Chrome when you call an undefined function.

Uncaught RangeError

        This is an error that occurs in Chrome when you call a recursive function that does not terminate. It may also happen if you pass a value to a function that is out of range.

FIX   

        To fix this error  add  number in the range of function

ReferenceError: event is not defined

        This error is thrown when you try to access a variable that is undefined or is outside the   current scope.

FIX

        To fix this error when using the event handling system, make sure we use the event object passed in as a parameter.


Reference

https://rollbar.com/blog/top-10-javascript-errors/

Comments

Popular posts from this blog

NULL VS UNDEFINED

NULL VS UNDEFINED        Undefined means a variable has been declared but has not yet been assigned a value. On the other hand, null is an assignment value. It can be assigned to a variable as a representation of no value. Also, undefined and null both are two different data types: undefined is a type itself (undefined) null is an object. var a;//undefined var b = null; var c=5; var d = a+c // NaN var e = b+c  //5   If  I am trying to do any mathematical  operation with null and number it gives me some  number as output,  instead of null if i am doing it with undefined and number the result is NaN null !== 0;    undefined !==0;

AUTH and CORS

   CORS 1. CORS is a mechanism that uses additional HTTP headers to tell browsers to give a web application running at one origin, access to selected resources from a different origin. A web application executes a cross-origin HTTP request when it requests a resource that has a different origin (domain, protocol, or port) from its own. 2. An example of a cross-origin request: the front-end JavaScript code served from https://domain-a.com uses XMLHttpRequest to make a request for https://domain-b.com/data.json. 3. For security reasons, browsers restrict cross-origin HTTP requests initiated from scripts. For example, XMLHttpRequest and the Fetch API follow the same-origin policy. This means that a web application using those APIs can only request resources from the same origin the application was loaded from unless the response from other origins includes the right CORS headers. 4. The CORS mechanism supports secure cross-origin requests and data transfers between bro...

JAVASCRIPT OBJECT & ITS INTERNAL REPRESENTATION

OBJECT Objects are same in all programming languages i.e they represent real-world things that we want to represent inside our programs with characteristics/properties and methods. In JavaScript Objects are kind of String/Number   Index Array represented inside curly brackets Var obj = { 1: “NAME”, "Maths" :100 } KEY VALUE PAIR In the above example obj is an object with 2 properties with key as 1 and Maths and value as Name and 100 .Here the index are called as KEY.KEY :VALUE pair together called as entries Object literals are a comma-separated list of key-value pairs wrapped in curly braces. Object literal property values can be of any data type, including array literals, functions, nested object literals or primitive data type. Obj Values   in the above can be accessed via Dot notation i.e obj.1 ,obj.Maths   or via a square bracket notation i.e obj[1] ,obj[“Maths”] Object.assign() METHOD As we discussed earlier in JavaScript Objects are kind of...