1

Hello I am at some new project and just saw something that could not understand.

I tried to make an easier example as of what we have here in project but the basis is something like the following.

  function getSomething (data: string )
   {
     console.log(data);
     //do something else with a
   }

   let data; //data get's loaded from backend
   getSomething(data ?? 'data 2');

As I have played with it, it seems that data get's a default value of 'data 2'.

I already know about typescript's default value in parameters. Are those 2 concepts related? I am familiar with the following logic

  function getSomething (data: string ='data3')
  {
   console.log(data);
   //do something else with a
   }

   let data;
   getSomething(data); //if data is undefined it passes 'data3'

What is ?? all about?

  • 3
    Does this answer your question? [Double double questionmarks in TypeScript](https://stackoverflow.com/questions/62426269/double-double-questionmarks-in-typescript) –  Feb 24 '21 at 13:23
  • Or this? https://stackoverflow.com/questions/11412639/double-question-marks-vs-if-when-assigning-same-var – WaitingForGuacamole Feb 24 '21 at 13:31

0 Answers0