Sunday, August 28, 2022

An version of a snippet of the mdn

This is the snippet of the MDN

        function multiply (a,b) {
            b = typeof b !== 'undefined' ? b:1;
            return a*b;
        }
        put(multiply(5));

This is a version to it, I think that the one above is interessant

        function secMult(a,b) {
            if(typeof b == 'undefined') {
                return a*1;
            } else {
                return a*b;
            }
        }

        put(secMult(21));
        put(secMult(4,5));

Specially because in the of MDN b= is brilliant used like the conditional if, making it shorter, the hard is that isn't imaginitive, so is good see that example, imagine that 'b = is' equal to 'if(...) {...}'. But is good see the one that I write because at that point you can imagine from where came the one of that I pick from the MDN, and think that programing isn't for you because is something new very hard to learn is just this writting code we can find something new, and shorter to use.

Rute Bezerra de Menezes Gondim





No comments:

Post a Comment