But this time, I feel that not only learning but keeping a record of each concept and topic, will keep me motivated to continue the course and complete it until it ends. Another reason to choose the freeCodeCamp was to come across this playlist by Florin pop. He has done an amazing job there.
/* */. Although both of them are valid comment specifiers. We use
// for single-line comments and
/* */(start with
/* and end with
*/) for multi-line comments. For eg.
// Single Line or inline comment
/* Multiple Line of Comments */
_but can't contain spaces and start with numbers.
We can as well assign a value to the variable using assignment
= operator as
myName = "Prashant";
You can also initialize a variable at the time of its declaration as
var myNum = 7; var anotherNum = myNum;
- When you don't initialize a variable, rather just only declare it, they hold the value
- Performing any mathematical operation with
undefinedwill result in
NaNwhich means Not a Number.
- Performing concatenation with
undefinedby adding a string literal to it will result in a string
myVar are different due to case insensitivity of letter
var a = 10 + 10; // assigned 20
var b = 15 - 5; // assigned 10
- We can multiply two numbers using
var c = 5 * 10; // assigned 50
- We can divide two numbers using
var d = 80 / 10; // assigned 8
Until now, we have just used some basic mathematical operation which we've seen already in mathematics. However, there are some other helpful mathematical operators like
- Increment a number by 1 using
++operator. Yes, I hear, you say this can easily be done as
var = var + 1;
- Decrement a number by 1 using
--operator. Similarly, as the increment operator, we can decrement a numerical value stored in a variable in a concise way as
Some other operations are
- You can create Decimal numbers by just assigning the variable to the floating value. For e.g.
var pi = 3.14;
is a valid decimal number. All other arithmetic operations described above can also be performed with decimal numbers. :)
- We have remainder operator i.e.
var rem = 7 % 3; // assigned 1
This operation is widely used for finding out even and odd numbers as a number properly divisible by 2 would be called as even, and odd otherwise.
/= etc. You can use them as
var a = 1; a += 5; // a = a + 5
Other shorthand operators work in the same fashion.