For example: var example = 1;
This would create a variable called 'example' with the value '1'. When deciding the name, you must remember that you are not able to start the name with a number.
Variables can hold different types of values, such as integers, doubles, characters or strings. An integer would be a single number (e.g. 5, 32, -642). A double is a number with a decimal point (e.g. 2.1, 54.66, -0.1). A character is a single character (e.g. d, T, ^) and a string is a list of characters (e.g Hello, WoRlD, hgfds). See below for examples:
The most important rule when working with variables is to never mix the type of variables together. This will make sense when we get in to the arithmetic.
It is possible to do arithmetic with variables such as add (+), subtract (-), divide (/) and multiply (*). When adding variables together, it is best to place the new value into a separate variable.
See an example of these below.
No comments:
Post a Comment