When do you need quotes?
cweinhofer last edited by
I just started setting up my MagicMirror and am a total newbie. I am not a coder / programmer – I’ve basically just mimicked the examples from the various modules in GitHub to do my configuration. So this is a pretty basic question, but one that other newbies may be wondering as well.
When entering a value for a config line, when do you need quotes?
At first, I just assumed you quoted everything. But I was changing something in my config file and noticed some unquoted values. After a little more investigation, I realized that there are a few values that only work if they are not quoted (e.g. plain numbers and boolean T/F).
Can someone confirm the specifics of this for us newbies?
In case I’m not being clear, it seems like you would do
without quotes but
And a bonus question, should it be double quotes, single quotes, or can you use either one?
maxbachmann last edited by
Those are different types of variables:
The first one is a number the second one a string. Boolean only has the values true and false which are exactly the same as writing 1 and 0. the true and false statement is there for readability in the code but gets replaced by 1 and 0 when executing the program
So when you put quotes to the number it is a text that includes this number, but you need it as a number you can use for example for calculations (obviously convertions are possible)
For strings usually you can use either double or single quotes and both will work. it is usually a thing of consistency (which on is already used) which one you choose.
However there are a couple advantages in using double quotes.
- JSON notation is written with double quotes (although it might work with single quotes aswell)
- double quotes are more convenient when your already familiar with other programming languages like C that often use double quotes for strings
- for people without programming experience double quotes are already familiar from their language where a text is marked with double quotes aswell
- When you need a single quote in the text you can write
“It’s a boy”, but you would have to write ‘It’s a boy’ using single quotes to mark that the single quote does not end the string.
However when you use double quotes in the string to mark a text inside it’s the other way around :
you could write ‘Simon says: “I am happy”’ but with double quotes you need to write “Simon says: “I am happy””
Hope I could clear the confusion a bit.