MagicMirror Forum

    • Register
    • Login
    • Search
    • Recent
    • Tags
    • Unsolved
    • Solved
    • MagicMirror² Repository
    • Documentation
    • Donate
    • Discord

    When do you need quotes?

    Tutorials
    2
    2
    820
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • C
      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

      port: 8080
      

      without quotes but

      units: "metric"
      

      with quotes.

      And a bonus question, should it be double quotes, single quotes, or can you use either one?

      1 Reply Last reply Reply Quote 1
      • M
        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.

        1. JSON notation is written with double quotes (although it might work with single quotes aswell)
        2. double quotes are more convenient when your already familiar with other programming languages like C that often use double quotes for strings
        3. for people without programming experience double quotes are already familiar from their language where a text is marked with double quotes aswell
        4. 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.

        1 Reply Last reply Reply Quote 3
        • 1 / 1
        • First post
          Last post
        Enjoying MagicMirror? Please consider a donation!
        MagicMirror created by Michael Teeuw.
        Forum managed by Paul-Vincent Roll and Rodrigo Ramírez Norambuena.
        This forum is using NodeBB as its core | Contributors
        Contact | Privacy Policy