Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

why optional chaining operator cannot work in electron's tutorial-preload

i’m learning electron’s docments by myself. in this example
https://fiddle.electronjs.org/launch?target=electron/v26.1.0/docs/fiddles/tutorial-preload
https://github.com/electron/electron/tree/v26.1.0/docs/fiddles/tutorial-preload

i tried to add an optional chaining operator in renderer.js like this

const information = document.getElementById('info')
information.innerText = `This app is using Chrome (v${window.versions.chrome()}), Node.js (v${window.versions.node()}), and Electron (v${window.versions.electron()})`

to

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

const information = document.getElementById('info')
information?.innerText = `This app is using Chrome (v${window.versions.chrome()}), Node.js (v${window.versions.node()}), and Electron (v${window.versions.electron()})`

but the versions info disappears.

i’m using electron v26.1 so nodejs version is 18. i checked node.green it says node18 has implements all optional chaining operator functions. why is this unfunctional? thanks in advance

>Solution :

You can’t make use of optional chaining on the left hand side of an assignment. For instance –

let a = { b: 1 };

a?.b = 4; // Throws SyntaxError: Invalid left-hand side in assignment
a.b = 4;  // No error

Check MDN Reference for more information.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading