Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial
Robert James
20,491 PointsPractical use
I am doing javascript foundations, which i know is just giving me an insight into JS but in what context would this sort of thing be used in web design?
As in using variables, console.log etc...
I have minimal understanding atm of JS but more so of what it would be used for, i know its the behavioral side of websites, but if anyone could try to explain a little more to where and when i might use it i would be grateful.
Thanks
3 Answers
Dave Evans
13,160 PointsVariables, in my opinion, are the bread and butter of JavaScript. Being able to set variables adds a dynamic ability to your site that otherwise might just contain some HTML and CSS. Whether it is setting a trigger for a scrollTo script or using variables for user based input, variables can add so much to a site.
I use console.log all the time to check variable data without stopping my script halfway through. By using console.log, I can easily see where specific variables might not be set correctly and can debug my code more accurately.
When I tutored in college on web development I would always break it down like this. Your website is a paper airplane. The HTML is the paper and the specific folds, your CSS is the color and what makes it visually appealing and your JavaScript is the model rocket engine that you duct taped to the back.
Robert James
20,491 PointsThanks for your response. Html and css i am very comfortable with, javascript is my next step.
I am only just starting the javascript foundation deep dive, and as i am slowly getting to grips with it but where we are just going through different things like variable and loops, what i feel isnt really being explained is how to apply it within a website!
Maybe, well hopefully, that will come further on as i work through the stages.
Thanks again
Nick Pettit
Treehouse TeacherHi Robert James,
JavaScript can be applied to websites and web applications in a huge variety of ways. You can use it to do simple things like reveal a modal window or trigger a CSS animation. You can also use it for more intermediate purposes, like fetching data from the server without refreshing the page. You can even build complex web apps that use JavaScript for things like page templates or browser-based games.
All of these things require foundational knowledge of the most atomic programming constructs in JavaScript, like variables, loops, arrays, if statements, and more. Even for something as simple as manipulating a page element, you'll likely need to traverse the DOM tree (your HTML) using a loop and then store a selected element in a variable. If you're working with JSON data fetched from a web server, you'll probably need to parse it and store things into an array. All of the basic language components can be used in concert to form more complex ideas, so even though they don't seem useful on their own, they become more useful later on in your learning.