dedlfix: Cast: String oder new String

Beitrag lesen

Tach!

try this:

let a = 5, b;
console.log(String(a));
console.log(a.toString());
console.log(String(b));
console.log(b.toString());

Was einem bei b nun lieber ist, muss man für sich entscheiden.

b ist keine Zahl und damit erstmal nicht von dem betroffen, was von der Aufgabenstellung bekannt ist. Abgesehen davon gibt es neben dem Typecast auch noch andere Wege, für einen falsy Wert einen Defaultwert zu bekommen, beispielsweise b || 0 oder b || ''.

dedlfix.

0 69

Cast: String oder new String

pl
  • javascript
  1. 0
    dedlfix
    1. 0
      pl
    2. 0
      Rolf B
      1. 0
        pl
        1. 1
          dedlfix
          1. 0
            pl
            1. 0
              dedlfix
              1. 0
                pl
          2. 0
            Rolf B
            1. 0
              dedlfix
              1. 0
                Rolf B
                1. 1
                  dedlfix
                2. 0
                  1unitedpower
        2. 0
          1unitedpower
          • javascript
          • typescript
          1. 0
            pl
  2. 0
    ursus contionabundo
    1. 0
      dedlfix
      1. 0
        ursus contionabundo
    2. 0
      pl
      1. 0
        ursus contionabundo
        1. 0
          pl
          1. 0
            ursus contionabundo
            1. 0
              pl
              1. 0

                Ganz unverblümt...

                ursus contionabundo
                • meinung
                1. 0
                  pl
                  1. 0
                    ursus contionabundo
                    1. -2
                      pl
                      1. -1
                        ursus contionabundo
                        1. 0
                          Felix Riesterer
                          1. 0

                            Frage immer noch offen!

                            pl
                            1. 0
                              dedlfix
                              1. 0
                                pl
                                • javascript
                                1. 0
                                  Felix Riesterer
                                  1. 0
                                    pl
                                2. 1
                                  dedlfix
                                  1. 0
                                    pl
                                    1. 0
                                      dedlfix
                                      1. 0
                                        pl
                          2. -1
                            pl
                            1. 0
                              Felix Riesterer
                              1. -1
                                pl
                                • zu diesem forum
                                1. 0
                                  Gunnar Bittersmann
                                  • meinung
                                  1. 1
                                    dedlfix
                                    1. 0
                                      Christian Kruse
                                      1. 0
                                        dedlfix
                                        1. 0
                                          Tabellenkalk
                                          1. 0
                                            Gunnar Bittersmann
                                            • logik
                                        2. 0
                                          Gunnar Bittersmann
                                          • logik
                                          1. 0
                                            dedlfix
                                            • meinung
                                            1. 0
                                              MudGuard
                                            2. 0
                                              Gunnar Bittersmann
                                      2. 1
                                        JürgenB
                                        1. 0
                                          Felix Riesterer
                                          1. 0
                                            Gunnar Bittersmann
                                    2. 0
                                      Gunnar Bittersmann
                                      1. 0
                                        Tabellenkalk
                                        1. 0
                                          Gunnar Bittersmann
                                          1. 0
                                            Rolf B
                                    3. 0
                                      Orlok
                                      • mathematik
                                  2. 0
                                    Gunnar Bittersmann
                                    • musik
                            2. 0
                              Gunnar Bittersmann
                              • meinung
                              • zu diesem forum
                            3. 0
                              ursus contionabundo
                              1. 0

                                (Ergänzung)

                                ursus contionabundo
                                1. 0
                                  Rolf B
                                  1. 0
                                    ursus contionabundo
                                2. 0
                                  Rolf B
                                  • meinung
                                  • performance
                                  1. 0
                                    ursus contionabundo
                                    1. 0
                                      Rolf B
                                      • humor
                                      • meinung