简体   繁体   English

function 中出现“变量未定义”错误的问题

[英]Issues within a function getting 'variable undefined' error

A few years back I wrote a javascript library for a simple task.几年前,我为一个简单的任务编写了一个 javascript 库。 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.我用它需要的值调用 function fixPersonnummer ,然后它崩溃了,说变量fixedPersonnummer没有定义。 I tried to add var and let but that makes the result become whatever int I give the var.我试图添加 var 和 let 但这使得结果变成我给 var 的任何 int。 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.在此代码示例中, removeStreckfixedPersonnummer未初始化。 Try to initialie this variables first.尝试先初始化这个变量。

is this variable "fixedPersonnummer" being used anywhere else in this file?这个变量“fixedPersonnummer”是否在该文件的其他任何地方使用? can add the lines where this function is called or lines above this function可以添加调用此 function 的行或此 function 上方的行

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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