#I need to understand why this piece of coding is only showing the first variable(just learning java)
31 messages · Page 1 of 1 (latest)
I need to understand why this piece of coding is only showing the first variable(just learning java)
Despite their similarity in name, Java and JavaScript are different languages and are not compatible with each other. This is a JavaScript server, but there are likely many Java-specific servers out there.
Why would it not?
The let-declared variable in the block ({}) is only visible in this block
Oh i am sorry. Its Javascript
Okay, so the variable outside the block is considered Global? and we can only print global?
No
What you print is the variable in the scope
The block is another scope
See #faq to learn modern JS
if you copy paste the log in the block, you will see first 2 then 15555
I understand now, thank you p35
@sharp frigate I am still learning to understand majority of it. As for .innerHTML i can only assume its considered a function within js, but i am not on that lesson yet. I was thinking maybe if i do change that then i would be able to output both of those number, but that is way beyond my scope rn.
One thing as a time, lmao. I do appreciate both of your guys help!
ya my comment didn't really apply, that's why I deleted it...
it's generally bad to use innerHTML but is fine here. just look into the security implications at some point.
no, innerHTML is not a function. it's a property of the element object.
I am confusing myself because i only know Python, so thank you.
Wait!
How can it not be a function?
It's a getter/setter
words = str.split()
print(len(words))```
.split()<----this could be considered property of the element object no? The object would be ``str``
or should i stop just comparing the two languages? ahah
There's Impatient JS ( #faq ) if you know another language
python is relatively close to JS however
i will start reading! appreciate it!!
yes, .split() is both a property and a function 😉 (but not a property of Element objects)
Gracias!!
Properties are ./[] accessed. A method is a function, but not every property is a function
Generative AIs (e.g. ChatGPT)
W3Schools
FreeCodeCamp
geeksforgeeks```
May i ask why not w3school, and geeksforgeeks? Those are like my heaven
The use of W3Schools is discouraged. It still features outdated information, and generally contains bad practices which are hard to discern by beginners. See https://www.w3fools.com/.
While it may serve as a reference, we recommend using other resources for learning such as https://javascript.info/ and https://developer.mozilla.org/en-US/docs/Web/JavaScript.
Check out our #faq for more references and learning opportunities.
(same for g4g AFAIK)
Cool