showing results for - "optional chaining in javascript"
Jo
05 Apr 2019
1Optional chaining: (?.)
2
3The optional chaining operator (?.) enables you to 
4read the value of a property located deep within a 
5chain of connected objects without having to 
6check that each reference in the chain is valid.
7
8The ?. operator is like the . chaining operator, 
9except that instead of causing an error if a reference 
10is nullish (null or undefined), the expression returns 
11a value of undefined. 
12
13When used with function calls, 
14it returns undefined if the given function does not exist.
15
16Example:
17
18const adventurer = {
19  name: 'Alice',
20  cat: {
21    name: 'Dinah'
22  }
23};
24
25const dogName = adventurer.dog?.name;
26console.log(dogName);
27// output: undefined
28
29console.log(adventurer.someNonExistentMethod?.());
30// output: undefined
Fernando
19 Feb 2020
1const greeting = object?.deepProp?.deeperProp?.greet
Zacharie
29 Mar 2019
1if (user?.team?.subscription?.invoices) {
2  //
3}
Claudio
12 Sep 2018
1let x = foo?.bar();
2
3if (foo?.bar?.baz) { // ... }
4
queries leading to this page
optional chaining benefitjs optional chaining arraywhy it is called optional chainingjavascript optional chaining operator typescriptusing optional chaining operator for function callsjs optional chaining operatoroptional chaining operatoroptional chaining jsoptional chaining javascript not working on producyionoptional chaining elsetanspile optional chainingoptional chaining js conditionoptional chaining js examplejs alternative to optional chainingoptional chaining with variablesoptional chaining nodeoptional chaining operatorthe optional chaining operator 28 3f 29 syntax highlightproblems on optional chainingjavascript optional chaining supportjavascript question mark dot operatoroptional chainoptional chaining when defining variablewhy not optional chain everything jhsoptional chaining operator es versionoptional chaining not working in node jsoptional chaining array javascriptoptional chaining javascipt ecmascript syntax optional chainingjavascript safe navigation operatoris there a alternative to optional chaining js 3fjavascript optional chaingingoptional chaining in nodejavascript object optional chainingwhat node version optional chainingmethod chaining optionaljs find with optional chainingwhat5s optional chaining in nodejsoptional chaining before optional chaining 3foptional chaining in place of 26 26javascript optional chaining es8optional chaining if else jschaining in es10optional chaining in jsoptional chain function callwhen to use optional chainingwhat is optional chaining in javascript 28 3f 29optional chaining javascript mdnwhat is optional chaining javascriptmdn optional chaining 3f object property operator jshow to use optional chaining typescriptjavascript error at optional chainingoptional chaining in js in arrayoptional chainghow to support optional chainingoptional chaining if jsoptional chaining reactoptional chaining in javascriptnodejs version optional chaining operatoroptional chaining es7javascript optional chainingjs optional chainigoptional chaining function calloptional chaining new es6optional chainign jsoptional chaining operator in javascriptoptional chaining with array javascriptis optional chaining supportted in node 3fcan you use optional chaining in javascriptjs optional chaining operator releasoptional chaining javascriptjavascript optional chaining ecmascript versionquestion mark js propertyquestion mark property javascriptjavascript property with question markoptional chainningjs optional chaining functionconditional chaining jsjavascript info optional chainingoptional chaining javascript 3f 3foptional chaining 27 3f 27optional chaining to call a functionwhat is optional chaining in javascript 28 3f 29 mediumjavascript optional chainingoptional chainingnode optional chaininghow to use optional chaining operatorjavascript operator optional chaining operatoroptional chaining javascript with booleanoptional chaining vs withou chainingoptional chaining js javascript infohow to install optional chaining javascriptalternative to optional chaining js 3foptional chaining for function callscan i use optional chainingoptional chaining in js with 2 question markjavascript optional chaining function calljs object optional chainingif and optional chainingoptional chaning jsoptional chaining 3f optional chaining operatorsoptional chaining nodejs versionoptional chaining while defining variableoptional chaining version nodeoptional chaining three variablesnode 10 optional chaininghow to use optional chaining in nodejs 12 what is optional chaining in javascript 28 3f 29 medium makinchaining ternary optionaljavascript optional chaining browser supportjs conditional chaining erroroptional chaining injsjs dynamic optional chainingoptional chaining for 5b 5d javascriptwhy to avoid optional chaining operatoroptional chaining es5optional chaining js versionoptional chaining acewhy does 2bjava not support optional chaining operator javascriptes6 optional chaining function calloptional chainiingjs optional chaining not workingelse in optional chaining 3f operator js optional chainingjavascript optional chaining 3f 3foptional chaing in jsfunction optional chainingoptional chaining trong javascriptoptional chaining node versionoptional chaining operator not workinghow to use optional chaining and nullishoptional chaining javascript arrayoptional chaining operator javascriptjs question mark propertyoptional chaingingoptional chaining with thisoptional chaining operator nodejs versionoptional chain operatoroptional chainignjavascript conditional chainingjs enable optional chainingoptional chaining with 5b 5doptional chaining es6optional chaining operator browser supportmdn 3f chaining operator in javascriptjavascript optional chainginoptional chaining nodejshow to enable optional chainingjavascript chainingjs question mark after propertyoptional chaining nodejs arrayes6 3f optional chainingoptionally chaining javascriptoptional chaining mdnjavascript optional chaining arrayjavascript is a symbol for optional chainingdefault value for optional chaining 3f js javascript before optional chainingjs optional chainingaccess object property question mark javascript optional chaining javascript is it best practicesoptional chaining inchain optional in jsoptional chaining anhoptional chaining 3f 3foptional chaing before optional chaining 3fjavascript optional chaining proposalsyntax error on in optional chaining jsoptional chaining operator es6optional chaining 28 3f 29optional chaining with variableoptional chaning on array lengthoptional chaining ecmascriptjavascript optional chain expressionoptional chainimgoptional chaining is jsoptional chaining still error jsjavascript chaining operator string to numberoptional chaining array jsnode version optional chainingis optional chaining es6optional chaining operatooptional chaining javascript supportjs optional chainoptional chaining not working nodeoptional chaininhgoption chaining javascript jsconfigjavascript question mark period operatoroptional chaining javascript not workingjs optional changing function call expected expressingones6 optional chainingoptional chainging javascoptional chaining examplein javascript optionaloptional chaining 26 26question mark when accessing property javascriptshould we do optional chainingoptional chaining 28 3f 29optional chaining operator supportoptional chainnig functionconditional chain javascriptjavascript optional chaininghow to check null for chain of objects in jsnull chaining jsproperty question mark jswhat is optional chaining in javascriptis security to use optional chaining operator optional chaining in jsnode js optional chainingjavascript optional chaining node versionsis optional chaining same as elvisnodejs optional chainingoptional chaining in javascript