Problem with javascript function

Asked

Viewed 27 times

-1

To having a problem of "Uncaught Referenceerror: nameValue is not defined", being that the "nameValue", is being passed to function, so no idea of what the problem.

Function :

 function cleanStorage(type, namevalue){
        console.log(nameValue)
        if(type == 'storage'){
            localStorage.clear();
            return [1, 'Sucesso ao limpar storage!']
        }

    if(type == 'item'){

        if (!localStorage.hasOwnProperty(nameValue)) {
            return [0, "Erro. Item a ser exluido não exite!"];
        }

        localStorage.removeItem(namevalue);

        return [1,'Sucesso ao exluir item!']
    }

    return [0, 'Erro. parametro passado é invalido'];


}

My call:

cleanStorage('item','teste')

1 answer

0


The problem is the spelling of the parameter name, in the function you declared as "namevalue", but in some places of the function you used "nameValue". You have to standardize all calls to "namevalue"

  • Bro bgd, and I looked like 100 times and I didn’t realize.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.