Is there something like the swift optional chaining in javascript?

MonkeyBonkey

I've been doing a lot of code likes this in javascript

if (params && params.profile && params.profile.address && params.profile.address.default)

where I have to check for each optional, it gets pretty tedious. Is there a better way in javascript that's similar to how swift would deal with optionals, e.g.

if let checked = params?.profile?.address?.default?

Dokinoki

There is no such operator in native JS.

However, there is a Babel plugin that will accomplish that, please check https://github.com/davidyaha/ecmascript-optionals-proposal

Also, please refer to Null-safe property access (and conditional assignment) in ES6/2015 for more references

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Java

Is there something like optionnal chaining for asignment in javascript

From Dev

Swift 3.0 Optional Chaining

From Dev

swift optional chaining with cast

From Dev

Optional chaining with Swift strings

From Dev

Optional chaining and Array in swift

From Dev

Optional Chaining in JavaScript

From Dev

Optional Chaining or ternary expression in Swift?

From Dev

Swift optional chaining doesn't work in closure

From Dev

Optional chaining used in left side of assignment in Swift

From Dev

Accessing boolValue in a NSNumber var with optional chaining (in Swift)

From Dev

Javascript: destructor or something like that

From Dev

Is there something like glob but for URLs, in JavaScript?

From Dev

How to use optional chaining while searching through a dictionary in swift?

From Dev

Is Swift optional chaining lazily evaluated left-to-right?

From Dev

optional chaining in Swift 3: why does one example work and not the other?

From Dev

Is something in Swift like LINQ in C#

From Dev

In swift, why can I set a computed property of a polymorphic variable via optional chaining, but not on an unwrapped optional?

From Dev

Is Swift optional chaining always done with the if let construction, or is it just done using a question mark with an optional?

From Dev

In swift, why can I set a computed property of a polymorphic variable via optional chaining, but not on an unwrapped optional?

From Dev

Swift: Why all my optional variable looks like "Optional(305.502)"

From Java

Optional chaining (?.) in nashorn

From Dev

Optional Chaining returning an Int

From Dev

Optional Chaining Not Working As Expected

From Dev

Chaining Optional.orElseThrow

From Dev

Optional chaining for constructor calls?

From Dev

Is there something like JavaScript's "split()" in the shell?

From Dev

Are optional protocols from Objective-C not something that should be done in Swift?

From Dev

an unexpected error while writing a piece of code from Swift programming by Apple(optional chaining)

From Dev

how to use GDataXML or something like DOM parser in swift?

Related Related

  1. 1

    Is there something like optionnal chaining for asignment in javascript

  2. 2

    Swift 3.0 Optional Chaining

  3. 3

    swift optional chaining with cast

  4. 4

    Optional chaining with Swift strings

  5. 5

    Optional chaining and Array in swift

  6. 6

    Optional Chaining in JavaScript

  7. 7

    Optional Chaining or ternary expression in Swift?

  8. 8

    Swift optional chaining doesn't work in closure

  9. 9

    Optional chaining used in left side of assignment in Swift

  10. 10

    Accessing boolValue in a NSNumber var with optional chaining (in Swift)

  11. 11

    Javascript: destructor or something like that

  12. 12

    Is there something like glob but for URLs, in JavaScript?

  13. 13

    How to use optional chaining while searching through a dictionary in swift?

  14. 14

    Is Swift optional chaining lazily evaluated left-to-right?

  15. 15

    optional chaining in Swift 3: why does one example work and not the other?

  16. 16

    Is something in Swift like LINQ in C#

  17. 17

    In swift, why can I set a computed property of a polymorphic variable via optional chaining, but not on an unwrapped optional?

  18. 18

    Is Swift optional chaining always done with the if let construction, or is it just done using a question mark with an optional?

  19. 19

    In swift, why can I set a computed property of a polymorphic variable via optional chaining, but not on an unwrapped optional?

  20. 20

    Swift: Why all my optional variable looks like "Optional(305.502)"

  21. 21

    Optional chaining (?.) in nashorn

  22. 22

    Optional Chaining returning an Int

  23. 23

    Optional Chaining Not Working As Expected

  24. 24

    Chaining Optional.orElseThrow

  25. 25

    Optional chaining for constructor calls?

  26. 26

    Is there something like JavaScript's "split()" in the shell?

  27. 27

    Are optional protocols from Objective-C not something that should be done in Swift?

  28. 28

    an unexpected error while writing a piece of code from Swift programming by Apple(optional chaining)

  29. 29

    how to use GDataXML or something like DOM parser in swift?

HotTag

Archive