Why use a secondary variable in the function?


#1

https://www.codecademy.com/en/courses/javascript-beginner-en-6LzGd/0/2?curriculum_id=506324b3a7dffd00020bf661

Using the second variable "val" seems redundant, when you can just divide the parameter "number" directly, as shown below. What are the applications of declaring the second variable as seen in the exercise?


var divideByThree = function (number) {
    
    console.log(number/3);
};


divideByThree(6);


#2

HI you rigth you should keep your code D.R.Y (Don't Reapeat Yourself)

What are the applications of declaring the second variable as seen in the exercise?

I don't see any application.


#3

This here teaches you the basics. In a simple function like this declaring a var maybe redundant, but it teaches you that it can be done and in the complex applications you will be building in the future youy have to do it.

Extra points to you for asking the question


#4

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.