'Javascript new function without assigning it to a var

Is there a risk in declaring and calling a function without assigning it to a var ?

Normaly, I put my javascript this way:

 $(document).ready(function (ev) {

        var myFunc =  function () { 
            init();
    
            function init() {
                initEvents();
            };
    
            function initEvents() {
                ...
            };
    
        }();

But since the var is never used, and could conflict with another one in the global namespace, I am thinking of doing this instead:

  $(document).ready(function (ev) {

        new function () { 
            init();
    
            function init() {
                initEvents();
            };
    
            function initEvents() {
                ...
            };
    
        }();

Seems to work, but any danger ?

Based on the comments received, I think the solution would be to do this instead:

$(document).ready(function (ev) {
    
                init();
        
                function init() {
                    initEvents();
                };
        
                function initEvents() {
                    ...
                };
});
   


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source