MCQs>IT & Programming>JavaScript>What's the output? var Apple = function() { var color = 'green'; var apple = { picked:false, pick: function() { this.picked = true; console.log (color); color = 'yellow'; }, change: function() { this.color = Math.random() > 0.5 ? 'yellow':'red'; } }; return apple; } var a = Apple(); a.pick(); console.log (a.color);
JavaScript MCQs
What will the following code will output? var Apple = function() { var color = "green"; var apple = { picked:false, pick: function() { this.picked = true; console.log (color); color = "yellow"; }, change: function() { this.color = Math.random() > 0.5 ? "yellow":"red"; } }; return apple; } var a = Apple(); a.pick(); console.log (a.color);
Answer
Correct Answer: "green" and then "undefined"
Explanation:
Note: This Question is unanswered, help us to find answer for this one