Explain this javascript function to me

Brant Snow
Brant Snow used Ask the Experts™
on
I was playing codewars, i came up with this
function nbDig(n, d) {
    // your code
    var count;
    count=0;
    while(n>0){
      var squared = (n*n).toString();
      var regex = new RegExp(d,"gi");
      var matches = squared.match(regex);
      if(matches){
            count = count + matches.length;
        }           
      n--;
    }
    return count;
   
}

However one of the best practices submitted was the following below

function nbDig(n, d) {
var res=0;
    for (var g=0;g<=n;g++){
      var square=(g*g+"").split("");
      square.forEach((s)=>s==d?res++:null)
    }return res;
}

I do not understand the (s)=>s==d

I believe that this is function(s){ s==d?res++:null}

Is that correct, can someone provide some good documentation or link for the (s)=> paradigm in javascript?
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Distinguished Expert 2017
Commented:
From the begging:
(s)=>....... as function(=>) with argument (s) : similar   function (s)

s==d?  Conditional (ternary) Operator replace the... If (s==d)

res++  Increment res (res=res+1) //True condition

:null  Null if (s==d) false.

Links:

JavaScript Arrow Functions Introduction

Conditional (ternary) Operator
Most Valuable Expert 2017
Distinguished Expert 2018
Commented:
Here is (in my opinion) the definitive link for JavaScript arrow functions

From this link
An arrow function expression has a shorter syntax than a function expression and does not bind its own this, arguments, super, or new.target. These function expressions are best suited for non-method functions, and they cannot be used as constructors.
square.forEach((s)=>s==d?res++:null)

Open in new window

square is an array
the forEach operates on the array and passes each element to the function provided
The arrow function
(s)=>s==d?res++:null

Open in new window

(s) - the current element in the array (square) being processed
The next bit is a ternary expression
(expr) ? if_true : if_false;

Open in new window

Same as
if (s==d) {
  return res;
}
else {
   return null
}

Open in new window

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial