When you create a JS function with one parameter.
For example,
| 1 | functionpersonalTest(type) |
| 2 | { |
| 3 | if(type=='A') |
| 4 | //todosth |
| 5 | elseif(type=='') |
| 6 | //todosthelse |
| 7 | } |
| 8 |
Please notice that if you invoke above function with “personalTest()”, you may not get correct result you expect. That’s because if you keep the parameter as blank, the ‘type’ will be equaled with ‘Undefined’. So if you want to make type==’’, you have to call the function by following way, personalTest(‘’)
本文详细解释了在JavaScript中创建单参数函数时,如何正确处理参数为空的情况,以及如何避免因参数为空而导致的预期结果错误。
1422

被折叠的 条评论
为什么被折叠?



