Forum Replies Created

Viewing 2 replies - 1 through 2 (of 2 total)
  • In JavaScript almost everything is an object, null and undefined are exception. When you try to access an undefined variable it always returns undefined and we cannot get or set any property of undefined. In that case, an application will throw Uncaught TypeError cannot set property of undefined.

    In most cases, you are missing the initialization . So, you need to initialize the variable first. Moreover, if you are not sure a variable that will always have some value, the best practice is to check the value of variables for null or undefined before using them. If you just want to check whether there’s any value, you can do:

    if( value ) {
    //do something
    }

    Or, if you do not know whether a variable exists (that means, if it was declared) you should check with the typeof operator .

    if ( typeof(some_variable) !== “undefined” && some_variable !== null ) {
    //deal with value
    }

    This error is almost always means you have a problem with recursion in JavaScript code, as there isn’t any other way in JavaScript to consume lots of stack. Sometimes calling a recursive function over and over again, causes the browser to send you Maximum call stack size exceeded error message as the memory that can be allocated for your use is not unlimited. It’s possible to cause infinite recursion in a fully promisified code, too. That can happen if the promises in a chain don’t actually perform any asynchronous execution , in which case control never really returns to the event loop, even though the code otherwise appears to be asynchronous. That’s when it’s useful to wrap your recursive function call into a –

    setTimeout
    setImmediate or
    process.nextTick

    Also, you can localize the issue by setting a breakpoint on RangeError type of exception , and then adjust the code appropriately. Moreover, you can managed to find the point that was causing the error by check the error details in the Chrome dev toolbar console , this will give you the functions in the call stack, and guide you towards the recursion that’s causing the error.

Viewing 2 replies - 1 through 2 (of 2 total)