Operators | Sololearn: Learn to code for FREE!
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!

5th Jul 2024, 7:28 AM
RaymanCoder
4 Respostas
+ 4
= 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).
5th Jul 2024, 7:52 AM
Bob_Li
Bob_Li - avatar
+ 3
yes but you must also actually have that class defined in your stylesheet or internal css. Then you can switch your style through javascript
5th Jul 2024, 8:34 AM
Bob_Li
Bob_Li - avatar
+ 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?
5th Jul 2024, 8:10 AM
RaymanCoder
+ 2
Thank you so much!
5th Jul 2024, 8:43 AM
RaymanCoder