2

I'm trying to get a stored number in the device's memory and parse it to integer using the method Integer.parseInt.

win:function(){
    this.reset();
    if(Integer.parseInt(window.localStorage.getItem("curLevel"))<this.levelNo)
    {
        window.localStorage.setItem("curLevel", this.levelNo+1);
        renderAllLevels();
    }
    $.mobile.pageContainer.pagecontainer("change", "#winlevel");
}

But when the function win is called I recieve the error Uncaught ReferenceError: Integer is not defined.

I used Integer.parseInt in other lines in my project and it worked without any error.

What is the potential error in using it here?

2
  • 3
    parseInt is a global function. There's no global object called Integer. If it wasn't causing errors before, it was probably in a different language. Commented Jan 13, 2016 at 20:01
  • When using the < comparison you don't really have to parse it, if one side is a number, the other is treated as a number Commented Jan 13, 2016 at 20:02

2 Answers 2

13

Java != JavaScript.

Use parseInt(value, 10).

Sign up to request clarification or add additional context in comments.

Comments

1

parseInt() is a global method, no need to link it to any object, you might want to change your code like so:

if( parseInt(window.localStorage.getItem("curLevel")) < this.levelNo )

1 Comment

I think you forgot the < this.levelNo part.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.