function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
KiransssssssssssssssssssKiransssssssssssssssssss 

how the values are passed to the function in JS

In JS how are the values passed. what i know is while calling a method based on the position of the values, those are assigned to the parameters. If the mthod is add(int a , int b) { ....  logic ....}

add(1,3) --> a =1, b = 3 and then the logic will happen. But in javascript i am facing some difficulty to understand how this is working.
 

In the below example, how are the values assigned to the parameters inside the function. i.e. validFields and inputComp.  the reduce function is just called with a function inside. 

 

({
    validateFields : function(component, event, helper)  {
        var isValid  = component.find('newContact').reduce(function(validFields,inputComp){
            inputComp.showHelpMessageIfInvalid();
            inputComp.set('v.validity',{valid:false,badInput:true});
            return validFields && inputComp.get('v.validity').valid
        },true);
      
    }
})

 

1 -- Please help me understand the concepthelp how are the variables getting the values in these type of scenarios.

2 -- Where can I find detailed info about using functions / variables this way.