There are three pilars of Front-End that we must know and that are:
Name Value
↑ ↑
| |
| |
var myName = "Vinod";
|
|
↓
Variable (key)
var myName = "Vinod";
var myAge = 26;
console.log(myName);
console.log(myAge);
Six Data types that are primitives:
typeof operator is used to know the data type of value or variable passed.
var myName = "Vinod";
var myAge = 26;
var iAmThapa = true;
// typeof operator
console.log(typeof(myName));
console.log(typeof(myAge));
console.log(typeof(iAmThapa));
Output ↓
string
number
boolean
Guess the Output
Difference between null and undefined?
What is NaN?
var myPhoneNumber = 9876543210;
var myName = "thapa technical";
console.log(isNaN(myPhoneNumber));
// this method can be used for checking if user is entering numeric value or not.
console.log(isNaN(myName));
if(isNaN(myPhoneNumber))
{
console.log("Please enter a valid phone number");
}
Operand
↑
|
console.log(5 + 20);
|
↓
operator
// 20 is also Operand
var x = 5;
var y = 5;
// console.log("is both the x and y are equal or not : " + x == y); // give wrong output (false)
// using new method of ES6
console.log(`is both the x and y are equal : %{x == y}`);
console.log(3 + 3);
console.log(10 - 5);
console.log(20 / 5);
console.log(5 + 6);
console.log("Remainder operator : " + 81 % 8);
Increment and decrement operator
var num = 15;
var newNum = num++;
console.log(num); // 16
console.log(newNum); // 15
var num = 15;
var newNum = ++num;
console.log(num); // 16
console.log(newNum); // 16
var a = 30;
var b = 10;
// Equal (==)
console.log(a == b); // false
// Not equal (!=)
console.log(a != b); // true
// Greater than (>)
console.log(a > b); // true
// Greater than or equal (>=)
console.log(a < b);
// less than (<)
console.log(a < b); // false
// less than or equal
console.log(a <= b); // false
var a = 30;
var b = -20;
// Logical AND (&&)
console.log(a > b && b > 0); // false
// logical OR (||)
console.log(a > b || b > 0); // true
// logical NOT (!)
console.log(!(a > b || b > 0)); // false
console.log("Hello World"); // Hello World
console.log("Hello" + " World"); // Hello World
var myName = "Vinod";
console.log(myName + " Thapa"); // Vinod Thapa
1- What will be the output of 3**3?
console.log(3**3); // 9
2- What will be the output, when we add a number and a string?
console.log(5 + "thapa"); // 5thapa
3- Write a program to swap two numbers?
var a = 5;
var b = 10;
var temp = a;
a = b;
b = temp;
console.log("The value of a is : " + a);
console.log("The value of b is : " + b);
4- Write a program to swap two numbers without using third variable?
var a = 5;
var b = 10;
a = a + b;
b = a - b;
a = a - b;
console.log("The value of a is : " + a);
console.log("The value of b is : " + b);
What is the difference between == and ===?
var num1 = 5; // number
var num2 = '5'; // string
console.log(num1 == num2); // true
console.log(num1 === num2); // false