I do at runtime so that I get the value from the function:

var dis = function calcD(a, b, c) { return b*b - 4*a*c; }; dis = dis(-4, 2, 1); 

Then you can simply call dis , which will have a specific value.
So, how can you immediately force the calcD script to execute and shove it into a variable without an additional line dis = dis(-4, 2, 1); ?

    1 answer 1

     var dis = (function calcD(a, b, c) { return b*b - 4*a*c; })(-4, 2, 1); console.log(dis); 

    However, this is somehow all useless and stupid ... for with the same ease it is possible not to fence this function at all and write dis = b*b - 4*a*c;

    • Apparently, it was necessary to write that the function only does return 2+2 , so that the uselessness would not be noticeable by example)) I don’t need this way. Thank. - VostokSisters
    • And the function is not available, right? That is, the name of the function in no way is available in the current osprey and consider that the name is meaningless to specify? - VostokSisters
    • And why are you framing the function with parentheses, if you can write var var1 = function(){//...}(); ? Style or need? - VostokSisters
    • имя указывать бессмысленно - yes ....... зачем вы обрамляете функцию скобочками - just visually separate the function with the body from its call ........ чтобы бесполезность не была заметна на примере - although it can be where in a separate module it may be necessary, I xs,) - Alexey Shimansky
    • Just in the module I use such a variable, when I call it, the width of the browser scroll is entered into the variable. - VostokSisters