Explain this javascript function to me

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?
LVL 4
Brant SnowAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Leonidas DosasCommented:
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
0
Julian HansenCommented:
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

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JavaScript

From novice to tech pro — start learning today.