'let' is similar to 'var' but has scope. let is only accessible in the block level it is defined
if (true) {let a = 40; console.log(a);}
console.log(a);
let a = 50; let b = 100;
if (true) { let a = 60;var c = 10;console.log(a/c); console.log(b/c); }
console.log(c); console.log(a);
'Const' is used to assign a constant value to the variable. And the value cannot be changed. Its fixed.
const a = 50;
a = 60;
const b = "Constant variable";
b = "Assigning new value";
const LANGUAGES = ['Js', 'Ruby', 'Python', 'Go'];
LANGUAGES = "Javascript";
LANGUAGES.push('Java');
console.log(LANGUAGES);
Intuitive expression interpolation for single-line and multi-line strings.
var customer = { name: "Foo" }
var card = { amount: 7, product: "Bar", unitprice: 42 }
var message = "Hello " + customer.name + ",\n" +
"want to buy " + card.amount + " " + card.product + " for\n" +
"a total of " + (card.amount * card.unitprice) + " bucks?";
function oldOne() { console.log("Hello World..!");} var newOne = () => {console.log("Hello World..!");}
var newOne = () - The first part is just declaring a variable and assigning the function (i.e) () to it. It just says the variable is actually a function.
=> {} - Then the second part is declaring the body part of the function. The arrow part with the curly braces defines the body part.
Default parameters are parameters which are given by default while declaring a function. But itβs value can be changed when calling the function.
let Func = (a, b = 10) => { return a + b; }
Func(20);
Func(20, 50);
Spread attributes help to spread the expression as the name suggests. In simple words, it converts a list of elements to an array and vice versa.
The null and undefined cannot be used to reference the data type of a variable. They can only be assigned as values to a variable
However, null and undefined are not the same. A variable initialized with undefined means that variable has no value or object assigned to it.
While null means that the variable has been set to an object whose value is undefined
User-defined types include Enumerations (enums), classes, interfaces, arrays and tuple.
console.log("Maximum value that a number variable can hold: " + Number.MAX_VALUE);
console.log("The least value that a number variable can hold: " + Number.MIN_VALUE);
console.log("Value of Negative Infinity: " + Number.NEGATIVE_INFINITY);
console.log("Value of Negative Infinity:" + Number.POSITIVE_INFINITY);
var num1 = new Number(177.234);
console.log("num1.toFixed() is "+num1.toFixed())
console.log("num1.toFixed(2) is "+num1.toFixed(2))
console.log("num1.toFixed(6) is "+num1.toFixed(6))
var num2 = new Number(7.123456);
console.log(num2.toPrecision());
console.log(num2.toPrecision(1));
console.log(num2.toPrecision(2));
var num3 = new Number(10);
console.log(num3.toString());
console.log(num3.toString(2));
console.log(num3.toString(8));
var num4 = new Number(10);
console.log(num4.valueOf());
var str = new String( "This is string" );
console.log("str.constructor is:" + str.constructor)
var str = new String("This is string");
console.log("str.charAt(0) is:" + str.charAt(0));
console.log("str.charAt(1) is:" + str.charAt(1));
console.log("str.charAt(2) is:" + str.charAt(2));
var str1 = new String( "This is string one" );
var str2 = new String( "This is string two" );
var str3 = str1.concat( str2 );
console.log("str1 + str2 : "+str3)
var str1 = new String( "This is string one" );
var index = str1.indexOf( "string" );
console.log("indexOf found String :" + index );
var index = str1.indexOf( "one" );
console.log("indexOf found String :" + index );
var str = new String("Apples are round, and apples are juicy.");
var sliced = str.slice(3, -2);
console.log(sliced);
var str = "Apples are round, and apples are juicy.";
var splitted = str.split(" ", 3);
console.log(splitted)
var str: string = "Apples are round, and apples are juicy.";
console.log("(1,2): " + str.substr(1,2));
console.log("(-2,2): " + str.substr(-2,2));
console.log("(1): " + str.substr(1));
var str: string = "Apples are round, and apples are juicy.";
console.log("(1,2): " + str.substring(1,2));
console.log("(0,10): " + str.substring(0, 10));
console.log("(5): " + str.substring(5));
var str: string = "Apples are round, and Apples are Juicy.";
console.log(str.toLowerCase( ))
var str = "Apples are round, and Apples are Juicy.";
console.log(str.toString( ));
var str = "Apples are round, and Apples are Juicy.";
console.log(str.toUpperCase( ));
var str = new String("Hello world");
console.log(str.valueOf( ));
Hello World program write and Execute in JavaScript