0
Operators
Hey, im new here. I have a question about operators in JavaScript. 1. Let's start with the operator (=) Do I have a certain variable for example: var X and I want to insert the number 3 into X. Is the number 3 X? Because it goes into it? What's on the right always goes into what's on the left? 2. The dot (.) operator. If for example I have var replay. And I write the following: replay.classList.add("div") So does the dot operator actually jump from the leftmost thing to the rightmost thing to work and at the end of the replay variable comes to classList and ends with add("div") to work? Thank you very much for your help!
4 odpowiedzi
+ 5
= is an assignment operator.
it assigns the right hand side value to the left hand side variable.
. is a property accessor.
if your var replay is assigned to a DOM element, then it have a classList property which in turn have an add method.
so replay.classList.add("div") calls that add method and adds the .div class to the replay element. (Btw, don't use .div as a class name. It's visually confusing to the div tag name).
+ 4
yes
but you must also actually have that class defined in your stylesheet or internal css. Then you can switch your style through javascript
+ 2
Thanks!
In connection with the (.),
I did not really understand?
Does it work like CSS?
Which means if I have .class1 .class2
So it jumps from the left and reaches the far right at the end to work?
+ 2
Thank you so much!