-1

I'm new to JavaScript. I was building a noob code for ordinal functions. I needed the last digit and, given my limited knowledge, couldn't figure it out. Found this code on the internet though and it solves the purpose.


    let getLastDigit = (str, num)=>{
    return num.toString();
  };
  let test2 = 2354.55;
  let lastDigit = +[...getLastDigit`${test2}`].pop();
  
  console.log("lastDigit-->", lastDigit, "<--typeof", typeof lastDigit);

While I understand that the code is converting the number into a string, popping it, and then returning the value as a number, can you please explain what (str, num) is doing over there and what's the "..." operator (couldn't find it anywhere)?

It will be a great help if you can explain how all lines are executing in general.

Thanks!

aragon404
  • 1
  • 1

0 Answers0