Values and Operators in JS
#teamtanayejschallenge- Part 1- Types of data and their manipulation option
Anything in your computer is data, let it be an image of you in Disneyland, a game or a document. All the data is stored in bits(small fragments of data), consisting of zeroes and ones.
Let’s jump to values in JS. There are 4 types of Data types (Actually 6, but for the sake of simplicity, let’s learn these 4 first). Namely — Numbers, String, Boolean and Undefined
1- Numbers — As simple as it sounds, it stores the value of data in form of numbers, both whole and decimal. It also holds negative and positive values between the range of -infinity & infinity.
var a = 14;
var b = 56.27;
var c = -45;// in the above code snippets, there are three data, stored by the // name of 'a, b & c' having a value attached to them, i.e, 15,
// 56.27 & -45 respectively. All these values are number of NUMBER // DATATYPE.
2- String — String values are anything that is put in any of these three quotes, which can hold value of any length, word, letters and sentences:
- ``- Backticks- Includes features to include JS code inside it
- ‘ ’- Single quotes- Normal way of declaring String
- “ ”- Double quotes- Same as above, matter of personal preference
var name = `Dash`;
var job = 'Developer';
var sentence = "Dash is a web developer."// as you see I have used three different types of quote marks, but // all of them essentially mean that the data type of the value is // of STRING DATATYPE
3- Boolean — Boolean are of two types; true and false.
var somethingRight = true;
var somethingWrong = false;// the above value of data are BOOLEAN DATATYPE
// they can't hold any other value, just true and false.
4- Undefined — Undefined datatype are for those values whose type we don’t know, whether it is number, string or boolean. It is yet to be defined.
Undefined value doesn’t do anything, and has very few use. Null is an empty value, which amounts to, well, null. There is no much difference between the two in practical ways, these are just the children of the design of the language when created.
var universe = null;// the variable universe doesn't contain anything. It is NULL.
// undefined values appear when a code snippet has to give some
// values but doesn't know what value to give.
Operators are like our Mothers. They work with some inputs (operands) and give us the output, just like our Mothers make us our favourite dishes using various ingredients.
There are three kinds of operators;
- Unary operator- These operators work on one operand, such as typeof()
typeof('Hello World!');// the output will be String, why? Because it is wrapped inside
// single quotes. Remember from the previous section? Awesome.
// it is just one example of unary operators, there are a few others // too.
- Binary operators- These work on 2 operands, such as +, -, /, *, %
console.log( 20 + 30 );// output will 50. As you see, '+' is a binary operator, working on // two operands (20 & 30).
- Ternary operator- There is only one of these. It works with three operands.
(conditon) ? statement-if-true: statement-if-false.
So, to sum up, JS has various different kinds of data, to help us write a program. There are many different operators to change the values stored, assigning them new values and such