Variables is the same thing in math. We assign a value to a letter or a name. Example, let x = 5; This is the same thing here. We use the keyword either let or const followed by the name and then initialize it with a value.
=================
const A = 5;
const B = 6;
let answer = 0;
function times(){
answer = A * B;
return answer;
}
=================
HTML
document.write(times())
Result:
30
Note:
1. You use the const keyword if the value in that variable will be the same all through out.
2. You use the let keyword if the value will change. In old javascript, they use var instead of let.
3. It is though initializing of variable that the compiler will determine the data type of the variable. In java, it is different, you specify the data type in the definition and then you initialize. In this, the compiler can pin point if the value you encoded has the same data type or not. In javascript, you can always assign a value with a different data type on that let variable.
Example:
===========
let x = 5;
x = "five";
===========
HTML
document.write(x);
Result:
five
Note: The code above was allowed since javascript is dynamically typed.
YOU ARE READING
Javascript Programming
RandomI am just documenting things what i learned online in here. I do express things in my own words. And I create my own program samples which serves as my practice. I do this so that when someday I would need some notes to review, I can just visit in h...
