The function returns undefined.

I have the following code:

alert('Returned value : ' + myid_templates_editor_image_id_generator()); //Generates unique id for every image created function myid_templates_editor_image_id_generator(){ (function($){ var a = 1; while(true){ if($('#myid_templates_editor_image_' + a).length == 0) { alert('Inside value : ' a); return a; } a++; } })(jQuery); } 

He warns twice:

enter image description here

enter image description here

Why is the value undefined returned? It should be 1 . Where am I missing?

+5
source share
1 answer

The myid_templates_editor_image_id_generator function myid_templates_editor_image_id_generator nothing. The only return expression ( return a; ) exits function($){...} , but does not extend to an external function.

+4
source

Source: https://habr.com/ru/post/1236201/


All Articles