js method returns undefined

Return undefined case 1:

When our object is not available, or the method is wrong

 

Return undefined case 2:

There is no return value due to the existence of judgment in the method

When there is a judgment in the method, but the data that does not meet the judgment is not returned, JS will not help you prompt and help you wrong like Java. It can return or not.

 

Return undefined situation 3:

After ajxa returns successfully, return is not written after ajxa ends.

In the method, ajax returns regardless of whether it is a success or an error, but we still return undefined after the call. The reason is: The
return return just jumps out of the ajax, but it does not end the method.


Therefore, you need to return at the end of the method, and there will be a return result. If you want to return the data obtained by the asynchronous call, you need to declare a variable in the method to get it;

Guess you like

Origin blog.csdn.net/xushiyu1996818/article/details/112690587