var x = 10;
Variables contain many advantages that support us along with the code. They indicate a clear and explicit meaning that goes through a journey of modifications and increments and results of operations that are similar to algebra of mathematics, but in fact it is all mathematics:
- Variables as illustration : Suppose we have three variables to add two numbers and put their value in the third, so we give an indication of the meaning of the first number, let it be first_num and the second number second_num, and the result is in a third variable named result whose name is clarified for people who want to read the code later to become as follows:
var first_num = 5; var second_num = 20; var result = first_num + second_num;
var default = 50; var test = default; test++;
- result num.
- result_num 2.
- _result num.
Variables as string
var my_string = "Hello World!";
Variables as a Boolean
Variables of type boolean can also be defined, which are the values that contain either true or false:
var myBoolean = null; var myBoolean = 1; var myBoolean = 0;
- They can be defined for later use in different parts of the code.
- A very short definition syntax that helps you to organize ideas, the use of variables is indispensable in all programming languages.
- Programmatic clarity during code analysis by pre-defining or using the formula var x = 15.
- Variables are generally the main clipboard for values that are loaded onto the screen.