JavaScriptNotes
1. Understanding variables and console.log
1.1
What is this stating?
- We are creating a variable, naming it x, and making it equal to 10
- Then we are logging to the console the value of x
1.2
- Creating a variable, naming it x, and setting it equal to 10
- Taking our variable and changing the value to x + 2 which in this case would read 10 = 10 + 2. Meaning now x is 12
- Logging out to the console the value of x. Since JavaScript is read top to bottom it will read the last value it was in this case 12
1.3
- Creating a variable x and making it equal to Hello
- Creating a variable y and making it equal to World
- Logging out the value of x - Hello
- Logging out the value of y - World
- Logging out the value of x+y - HelloWorld
- Logging out the value of x + a space + y - Hello World
Why did x+y run all together? If we had declared another variable called z and made that x+y what would the result have been?
Use CodePen to test it live here are the examples
https://codepen.io/WolfsVeteran/pen/LYRKKom?editors=1012
1.4
- Creating a function and calling it Hello
- when the function is called on print to the console 'hello'
- and Return the number 15 to the webpage only
- Creating a variable called result and calling on the function hello which will print in the console 'hello' and return the number 15
- logging out the word 'Dojo'