Learning Javascript Part II
Writing computer programs is all about controlling information. Information is called data in programming that we store in our PC programs. For instance, your pet's name is a bit of information, as is its breed and it will be called data.
In JavaScript, there are three basic types of data: numbers, strings, and Booleans. Numbers are used for representing integer values like this:
5;
Strings are used to represent any kind of text. For example your pet'sname can be represented like this:
"My pet's name is kitty";
I know i am bad at giving examples but hope it gave you a idea about strings.
Next is Booleans. Booleans are values that can be true or false like you can assign the value true to sentence "My pet's name is kitty".
There are distinctive approaches to work with every data type. For instance, you can multiple numbers with each other, however you can't do it with two strings having two numbers.
For Example:
Similarly with Booleans, you can verify whether two values are both true.
Variables
In javascript you can give names to values so that you can use these values later on.
You can think about a variable as a container that you can fit one thing in. In the event that you put something else in it, the primary thing leaves. For instance, here's the manner by which you'd make another variable called catname
Write this in the browser's console window.Hit enter and you will get a message in next line as undefined,which simply means that the catname doesn't have any value. This above step is known as declaration.A variable is an address in memory so we just now named a memory space but this is currently empty.To give value to this we write in console the above line without semicolon as the semicolon means the line ends here and put equal sign in front of it then write the value you want to give.I want to store the the name "kitty" in this variable.
The variable catname now stores the value kitty. When you first give value to a variable it is known as initialization.
Did you noticed that we gave a string value to this variable but you may give a number or boolean value to it like shown below.You can change the value from a number to string or to boolean Javascript won't mind it but will simply overwrite it.
Some Rules:
The variable name catname is known as identifiers.These can be long or short.lets look at the rules for writing these :They may contain letters, digits, underscores, and dollar signs.
It must start with a letter
Remember these names are case sensitive
Some reserved words such as JavaScript keywords can't be utilized as names.
Operators
Lets learn how to change the variable's value after its initialized. To do this we can simply give it a new value as we earlier did or we can perform some operations on them.
To perform operations on variables javascript offers some operators. For those who is thinking what an operator is "An operator is a symbol that makes the script perform a specific mathematical or logical manipulation.".So lets learn about them,
Arithmetic Operators
It is used to perform mathematical calculation
x = 2 + 4; // 6 addition
x = 7 - 2; // 5 subtraction
x = 3 * 5; // 15 multiplication
x = 100 / 10; // 10division
Assignment Operators
x = 0;
Increment and Decrement Operator
In JavaScript increasing by 1 is called incrementing, and decreasing by 1 is
called decrementing. The quick way to do this is ;
catAge++; // catAge = catAge+1;
catAge--; // catAge = catAge-1;
Comparison Operators
These return true or false based upon comparison of two values
num = (2 == 3); // False - equal to
num = (2 === 3); // False - identical
num = (2 !== 3); // True - not identical
num = (2 != 3); // True - not equal to
num = (2 > 3); // False - greater than
num = (2 < 3); // True - less than
num = (2 >= 3); // False - greater than or equal to
num = (2 <= 3); // True - less than or equal to
There are some other operators but we are not going to discuss about them here
So this is it for this post, next time we are going to learn about Arrays in javascript so please subscribe to Deecoder and share this post if you like this.
Great post! I don't even know what javascript but it was pretty cool to see what you've learned!
ReplyDeleteThanks
Delete