In chapter 34 of Smarter Way to Learn JS book, in this exercise:
Create a Date object for the current date and time.
1-Extract the year.
2-Reset the Date object a century back.
3-Display the date Object in an alert.
The solution is
1- var now = new Date(); 2- var nowYear = now.getFullYear(); 3- now.setFullYear(nowYear - 100); 4- alert(now);
What I did not understand is line 3. Why don’t we write this code instead:
now = now.setFullYear(nowYear - 100);
These two types of codes yeilds different results.
If I understood well the line 3 of the first example should be inherently written that way, I have just have to learn that syntax no need to overthink.
If you have a better analysis or an interesting link about this issue feel free to reply.