2

I'm looking at a new codebase right now and I've never encountered this before. Is it just checking for whether or not items.length > 0?

<div className={cn('input-dropdown-wrap', 
    { 'input-dropdown-wrap--active': isActive && items?.length })
}>
Mike K
  • 7,621
  • 14
  • 60
  • 120
  • is it JS or TypeScript? – Meir Sep 11 '19 at 08:49
  • 1
    It's `Optional chaining` https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Optional_chaining – Giang Le Sep 11 '19 at 08:49
  • Well do you remember errors like `can read property 'prop1' of undefined`, so to avoid these errors we can manually check the object is defined & its property 'prop1' can be read or you can use this `?.` to just do that for you. – vinayakj Sep 11 '19 at 09:39

0 Answers0