JavaScript variables in the real world

I’m trying to wrap my brain around the concept of creating and assigning variables. I’ve worked all the way through the Magic 8 Ball but not without tons of included Tips.

I guess my first, and probably the biggest question comes down to application. I understand that in the exercises that:

let userName = "my name";

can be defined within the code. But how does that translate into the website that a user would experience? It seems like the practices all make this variable an assigned one. Not understanding how this will affect the user experience is making it hard for me to comprehend what exactly this all means. Can someone please help me connect the dots here? Thanks everyone!

https://www.codecademy.com/paths/web-development/tracks/getting-started-with-javascript/modules/learn-javascript-introduction/lessons/variables/exercises/var

Hey @byte8999933367,

That is a very good question :wink: .

Basically a website is build using HTML for structure and CSS for styling.
A Javascript file or files can be linked to a website in the HTML for the purpose of creating interactivity and performing operations.

Manipulating the website it does by accessing the DOM ( Document Object Model) of a page. Javascript can be used to make menus appear upon clicking a button, build in image sliders, changing colours after a certain action etc.

Operations may be in the form of say you want to make a calculator website, the calculations operations can then be done using Javascript. The DOM manipulation is used to display the calculation output, i.e. by changing a text on the page.

But what about the user input? Well in HTML there is such a thing as form element where the user can enter a value which is then transferred to the server using the POST method. (This may be a bit complex to understand.) Javascript can then be used to read this data and store them in a variable like for instance userName.

The Codecademy Pro section has quite a significant amount of lessons about interactive Javascript websites as part of the Web development Path. You may want to look into that to learn about this topic.