Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

127
Views
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() {
                    ...
                };
});
   
about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!