Introduction: Reserved Words
A variable is a name that refers to a piece of data that we frequently want to use to in our code.
We can use variables in JavaScript like so: https://raw.githubusercontent.com/finsweet/jqueryCourse/main/variables/ex1.js?actionable=false
Variable initialization is simply naming pieces of data. For example when you want to define the minimum height of a div, we can write: https://raw.githubusercontent.com/finsweet/jqueryCourse/main/variables/ex2.js?actionable=false
In the the above code, we give number 10 the name min_height.
const is a keyword that is used to describe the min_height variable.
It denotes that the value of min_height is constant and will not change.
If the value of min_height needs to be changed in any part of the code, then we would write our min_height variable as: https://raw.githubusercontent.com/finsweet/jqueryCourse/main/variables/ex3.js?actionable=false In addition to storing numbers, variables can also be used to store other data types like characters, strings, objects and true/false values.
If a developer wants to store the name of some heading he might write: https://raw.githubusercontent.com/finsweet/jqueryCourse/main/variables/ex4.js?actionable=false
Depending on where the variable is declared, it can be known as a global variable or a local variable.
A global variable can be used anywhere within your script but a local variable can only be used within the function that it is declared in.
The following is a list of names that cannot be used when naming JavaScript variables, functions, methods, loop labels, or objects:
abstract, else, Instanceof, switch, boolean, enum, int, synchronized, break, export, interface, this, byte, extends, long, throw, case, false, native, throws, catch, final, new , transient, char, finally, null, true, class float, package, try, const, for, private, typeof, continue, function, protected, var, debugger, goto, public, void, default, if, return, volatile, delete, implements, short ,while, do, import, static, with, double, in, super.
$(document).ready(function(){
XT1
});
</script>
Live demo
$(document).ready(function() {
XT1
});
</script>