PrepAway - Latest Free Exam Questions & Answers

2 Comments on “Which code should you use?

  1. Vitalii Shevchuk says:

    Both variants C and D are currect.
    function sqr2(){
    return a * a;
    }

    function sqr(a){
    this.a = a;
    this.sqr2 = sqr2;
    console.log(this.sqr2());
    }

    sqr(2); //4
    function sqr2(){
    return this.a * this.a;
    }

    function sqr(a){
    this.a = a;
    this.sqr2 = sqr2;
    console.log(this.sqr2());
    }

    sqr(2); //4




    0



    0
  2. Loris says:

    Option B is a valid method too.

    function square(side) {
    this.side = side;
    this.area = calcArea;
    }

    function calcArea(obj) {
    return obj.side * obj.side;
    }

    var sq = new square(10);
    console.log(calcArea(sq));

    D options requires the using of “call” method.

    Which is the right answer?




    0



    0

Leave a Reply