Issue about changing elements of a date and time syntax in JS

Issue about changing elements of a date and time syntax in JS
0

#1

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.


#2

The new Date() returns an object which has several properties and methods. setFullYear is one of those methods. The dot syntax is used because now is an object.