Navigation

    Logo
    • Register
    • Login
    • Search
    • Recent
    • Tags
    • Unread
    • Categories
    • Unreplied
    • Popular
    • GitHub
    • Docu
    • Hilfe
    1. Home
    2. Deutsch
    3. Skripten / Logik
    4. JavaScript
    5. Variablen im String

    NEWS

    • Neuer Blog: Fotos und Eindrücke aus Solingen

    • ioBroker@Smart Living Forum Solingen, 14.06. - Agenda added

    • ioBroker goes Matter ... Matter Adapter in Stable

    Variablen im String

    This topic has been deleted. Only users with topic management privileges can see it.
    • bahnuhr
      bahnuhr Forum Testing Most Active last edited by

      Text Variablen hab ich immer so eingebunden:

      const v_Test = "abc";
      log ('Dies ist ein ' + v_Test);
      

      Und dies klappt auch wie immer.

      Dann hab ich hier im Forum gefunden, dass man dies auch einfacher mit einem $ einbinden kann.
      Im Netz hab ich auch folgendes Beispiel gefunden:

      const name = "Chris";
      const greeting = `Hello, ${name}`;
      console.log(greeting); // "Hello, Chris"
      

      und dies klappt auch.

      Wenn ich dann aber mein Beispiel umstelle, und zwar so:

      const v_Test = "abc";
      const zusammen = 'Dies ist ein ${v_Test}';
      console.log (zusammen);
      

      bekomme ich im log:

      script.js.Scripte.test9: Dies ist ein ${v_Test}
      

      Warum klappt dies nicht ?

      1 Reply Last reply Reply Quote 0
      • bahnuhr
        bahnuhr Forum Testing Most Active last edited by

        habs geklärt.
        Der Text muss in sogenannte backticks gesetzt werden.
        Also so:

        const zusammen = `Dies ist ein ${v_Test}`;
        

        Dann klappt es.

        haus-automatisierung 1 Reply Last reply Reply Quote 1
        • haus-automatisierung
          haus-automatisierung Developer Most Active @bahnuhr last edited by

          @bahnuhr Richtig. Die nennen sich template literals. Siehe auch

          https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals

          1 Reply Last reply Reply Quote 0
          • First post
            Last post

          Support us

          ioBroker
          Community Adapters
          Donate

          955
          Online

          31.8k
          Users

          80.0k
          Topics

          1.3m
          Posts

          javascript
          2
          3
          139
          Loading More Posts
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes
          Reply
          • Reply as topic
          Log in to reply
          Community
          Impressum | Datenschutz-Bestimmungen | Nutzungsbedingungen
          The ioBroker Community 2014-2023
          logo