Navigation

    Logo
    • Register
    • Login
    • Search
    • Recent
    • Tags
    • Unread
    • Categories
    • Unreplied
    • Popular
    • GitHub
    • Docu
    • Hilfe
    1. Home
    2. Deutsch
    3. Skripten / Logik
    4. JavaScript
    5. Verständnisfrage "if"

    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

    Verständnisfrage "if"

    This topic has been deleted. Only users with topic management privileges can see it.
    • E
      ErazorVIP last edited by

      Hallo,
      ich habe mal eine Frage (siehe Bild)

      Screenshot 2021-12-26 085910.png

      Wiso reicht es nicht wenn ich
      if(status) {
      oder
      if(!status) {

      abfrage?

      Muss ich ich zwangsmäßig == true und == false schreiben??

      liv-in-sky paul53 Xenon OliverIO 4 Replies Last reply Reply Quote 0
      • liv-in-sky
        liv-in-sky @ErazorVIP last edited by

        @erazorvip

        muss ohne "==true" funktionieren

        kann es sein, dass die var status kein boolean ist , bzw der dp, der da gelesen wird?

        1 Reply Last reply Reply Quote 0
        • paul53
          paul53 @ErazorVIP last edited by

          @erazorvip sagte: Wiso reicht es nicht wenn ich

          if(status) {
          oder
          if(!status) {
          abfrage?

          Es genügt so. Besser:

          if(status) {
             // Aktionen bei true
          } else {
             // Aktionen bei false
          }
          
          1 Reply Last reply Reply Quote 0
          • Xenon
            Xenon Forum Testing Developer @ErazorVIP last edited by

            @erazorvip mit
            console.log(typeof VALUENAME) bekommst du den type in der Konsole ausgegeben. Dann siehst du, ob du überhaupt einen bool vergleichst

            1 Reply Last reply Reply Quote 0
            • OliverIO
              OliverIO @ErazorVIP last edited by OliverIO

              @erazorvip

              Wenn Status einen nicht leeren String enthält, dann ist er immer true
              Auch wenn „false“ drin steht.
              Vergleiche truthy und falsy

              https://developer.mozilla.org/de/docs/Glossary/Falsy
              https://developer.mozilla.org/de/docs/Glossary/Truthy

              1 Reply Last reply Reply Quote 0
              • T
                ticaki Developer last edited by ticaki

                Der Vollständigkeit halber: status ist false wenn folgendes Zutriff:

                status == 0
                status == null
                status == undefined 
                status == ''
                status == false
                status == NaN
                

                EDIT: Not a Number ergänzt

                @oliverio sagte in Verständnisfrage "if":

                @erazorvip

                Wenn Status einen nicht leeren String enthält, dann ist er immer true
                Auch wenn „false“ drin steht.

                let a = 'false';
                if (a) log('istrue');
                
                //javascript.0 (1292) script.js.Test.nur_test: istrue
                

                hast du wohl anders gemeint als man es verstehen kann

                OliverIO paul53 2 Replies Last reply Reply Quote 0
                • OliverIO
                  OliverIO @ticaki last edited by

                  @ticaki
                  Ne genauso

                  T 1 Reply Last reply Reply Quote 0
                  • T
                    ticaki Developer @OliverIO last edited by

                    @oliverio
                    Oh man... lesen will gelernt sein. sry

                    1 Reply Last reply Reply Quote 0
                    • paul53
                      paul53 @ticaki last edited by

                      @ticaki sagte: Der Vollständigkeit halber

                      NaN liefert auch false.

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

                      Support us

                      ioBroker
                      Community Adapters
                      Donate

                      825
                      Online

                      31.9k
                      Users

                      80.1k
                      Topics

                      1.3m
                      Posts

                      6
                      9
                      547
                      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