Beginner's query on "electron-quick-start"


I learned of Electron only earlier today, and after a little trial-and-error succeeded in downloading and running “electron-quick-start”, and then in modifying it to change functionality and to bring it into line with my own coding conventions. But I am completely bemused by the line “let mainWindow”. I understand from the accompanying notes that this may have something to do with keeping the window alive after garbage collection, but I neither understand the syntax nor the semantics of that line. Could anyone explain, please ?


Welcome on Electron !
Maybe a short explanation :
mainWindow is an variable that you will have need used in your “main” and “renderer”

Good luck for your projects with Electron


Many thanks, Shmuel. In fact, it was not the use of “mainWindow” that mystified me, but rather the use of "let " without a following assignment. However, I now see from an example at that a bare "let " construction is permitted (“let foo // that’s ok (foo === undefined)”), so all is now clear, but from the perspective of clarity I would personally have coded that line as “let foo = undefined”. Brevity may have its place, but clarity is (or should be) essential.


Atom/Electron adhere to Javascript Standard style where if you write let a = undefined you get an error:

It’s not necessary to initialize ‘a’ to undefined.


With respect, I would not interpret that message as an error message. On a scale of 1 to 5 (success, information, warning, error, fatal error), I would class that as a 1 (informational). The statement says it is unnecessary — it doesn’t say it is wrong.


I’m not here to argue with you about your preferred javascript style or the semantics of errors and fatal errors; I was merely pointing out why the examples are the way they are. Your issue is that you are not familiar with javascript idioms not that the documentation uses a confusing or obscure code style.


My “issue”, John, as you term it, is that the example cited is opaque as-written (sufficiently opaque that I needed to seek an explanation of it here, whence this thread), and it is therefore not a good example; the fact that it conforms to Javascript Standard style is neither here nor there — examples, if they are to be genuinely useful, should be immediately transparent to the reader, and since “let a = undefined” is (a) valid JavaScript, (b) generates only an informational message from the JSS checker, and © would be immediately clear in meaning even to the most junior programmer, then I believe that for pedagogical reasons it would be better to use that construct in the example. By all means use “let a” in your own code, if you prefer brevity to transparency, but eschew such coding in examples which are intended to educate, not confuse.