简体   繁体   中英

Issues within a function getting 'variable undefined' error

A few years back I wrote a javascript library for a simple task. Today I had to visit it again, and I am not happy with my code. If it would just run... I know it ran back then but now I have no clue why it doesn't.

I call the function fixPersonnummer with the values it needs and then it crashes, saying that the variable fixedPersonnummer isn't defined. I tried to add var and let but that makes the result become whatever int I give the var. What have I done wrong?

function fixPersonnummer(personnummer, svarsLangd) {
    var len = personnummer.length;

    if (len === 13 && parseInt(svarsLangd) === 10) {
        removeStreck = removeDash(personnummer);
        fixedPersonnummer = removeCentuary(removeStreck);
    }
...
  • In this code example removeStreck and fixedPersonnummer not initialized. Try to initialie this variables first.

is this variable "fixedPersonnummer" being used anywhere else in this file? can add the lines where this function is called or lines above this function

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM