In this blog I am going to discuss some important and basic concepts of Java Script.
Let’s see one by one;
Key Capsule 1:-
So what happen when we declared
Capsule 1:- Here name stores by default undefined;
if we print using console.log(name)
o/p :- undefined.
Key Capsule 2:-
What you think what will be the out put ?
O/P :- “Surya”
Capsule 2 :- In java script although I declare the variable once again it won’t loose the value.
Key Capsule 3:-
what you think what is the out put ???
Capsule 3:- In java script if any numeric values comes after the string then the Plus (+) operator work like as a concatenation operator where as if the numeric value comes before the string then plus (+) operator works and it show addition of number then it concatenate the string.
Key Capsule 4:-
var studentName=”Rajanikant” ;
What will be the out put ??
Key Capsule 6 :-
How to print a string like this;
“The name is “Surykant”; he is a blogger.”
I want to print suryakant with the double quot.
We can write;
var data=”The name is \”Suryakant\”; he is a blogger”.
Same for single quto;
var data=”It\’s looking good.”
Most Important Key Capsule 7:-
Difference between == and === operator
“== “ operator is used to check directly the value where as “===” equality operator check the equality and types.
See bellow examples;
Test Case 1:-
var y= “surya”;
Note :- Here the output true for both the case because both are storing same value and both are of same type
Test Case 2:-
var y=new string (“surya”)
Scenario:- Here some of us might think that why it returns true ?
This question also came to my mind; because the second one is reference type; as we know inside reference type variable it stores the address of that value i.e “surya”.
So how both are equal then ??
Here important thing to understand that what actually happen when we comparing the value using double equality operator (“==”).
When we using double equality operator (“==”) to compare then this operator perform a type conversion while comparing two things; so in the above example when we compare x and y, although y is a object type it is converted to string type while comparing so both are get same type with value so it returns as true.
Where as triple equality operator (“===”) never do any type of conversion while comparing; it only check the type and value if both are same then it returns true other wise returns false.
Key To Remember :– So if we check any two reference/object type variable using triple equality operator (“===”) then it always return false; same for double equality operator (“==”) also return false; but if both are reference type pointing to same location then “===” operator return true.
Let’s clear; both reference type/object type pointing to same location means;
var obj=new string(“surya”);
Now if we check; obj===obj then we get output as true.
Capsule 7 :- What we learn form the above :-
Double equality operator(“==”) do conversion before checking while triple equal to operator(“===”) never do any conversion before checking it just check the type and value.
var c=new string(“surya”);
Now; a===a // True ; b===b // True; c===c //True
Again if i declare a new object type variable;
var d=new string(“surya”);
Now; c===d // False
Note :- Although ‘c’ and ‘d’ are the same type still it return false because after checking the type it will check the value inside it; both are pointing to different location so both have different value so it return false.
if we write; c==d
Note :- Now what happened both are converted to reference type; and due to both pointing different location; so it return false.
Key To Remember :- Due to the above reason double equality operator (“==”) called as loose equality operator where as triple equality operator (“===”) called as strict equality operator.
Test Case 3:-
var y=new string (“surya”)
Note :- Here the output is false because “===” operator is used to check type and both having different types so it return false.
Test Case 4:-
var x=new string(“surya”);
var y=new string (“surya”);
Ans:- In java script data types are classified into two types such as value type and reference type.
Under value type we have data type like;
Int, string,number,Boolean,null and etc.
Where as under reference type we have data type like;
Combine this all we said all these are object type.
Note:- Value types are directly stored value in side the variable where as reference type are stored the address of the object and that address pointing to the actual value location.
Key Capsule 8 :–
In Java script we have different global methods for Number such as;
Important Test Case:-
Test Case 1 :- parseInt(“10 Year”) //O/P- 10
Test Case 2 :- parseInt(“Year 10”) //O/P – NaN
Key Capsule 9:-
Note:- stdArr is a special type of object which store different type of object inside it.
Join Method in Array:-
For eg:- var arr=[“Ram”,”Hari”,”Madhu”]
so the o/p Ram * Hari * Madhu.
Key Capsule 10:-
This is indicate that we can not use a variable without declaring it. So if we use a variable without declaring it then it’s gives you an error.
Note :- Use strict can be write at the top of the script.
console.log(a) // Error because we did not declare the variable a.
Hope above concept helps you in understanding the basic concept; will see more on coming days.
Thanks for reading; have your feedback in comment box if you have any doubt in any test case.