Answers for "question mark dot javascript"

1

question mark dot javascript

const adventurer = {
  name: 'Alice',
  cat: {
    name: 'Dinah'
  }
};

const dogName = adventurer.dog?.name;
console.log(dogName); //undefined, doesn't return error
const catName = adventurer.cat?.name;
console.log(catName); //Dinah
Posted by: Guest on July-22-2021
4

javascript question mark

//This is what is called a 'Conditional operator'
let result = condition ? value1 : value2
//               ^^        ^^      ^^
let result =  1 == 2   ?  "YES" : "NO!"
console.log(result)  //output: "NO!"

//Basically a short form of an if-else statment
Posted by: Guest on March-11-2020

Code answers related to "question mark dot javascript"

Code answers related to "Javascript"

Browse Popular Code Answers by Language