const animal = ["tiger", "lion","elephant"];
animal.sort();console.log(animal);
let arr = [1,11,2,3,112,6];
arr.sort((a,b) => a-b);
console.log(arr);
const arr1 = ['1','2','3','11','4','53','56','53','5','23'];
arr1.sort((a,b)=>b-a);
console.log(arr1);
let arr2 = [2,1,24,37,33,65,52];
arr2.sort();
console.log(arr2);
Mutable Data Types:
mutable data types are those values whose values can be changed after they are
created.
// 1) array:
const arr = [1,2,3];
arr.push(4);
arr[1] = 5;
console.log(arr);
// 2) object:
const person = {name: 'pranesh', age: 26};
console.log(person);
person.age = [25,35,45,55,65,75,85,95,105];
console.log(person);
person.city = 'coimbatore';
console.log(person);
Immuteable data types:
Immutable data types are those whose values cannot be changed after they are created.
// 1) strings:
const str = "Hello";
const newStr = str.concat(" world");
console.log(str);
console.log(newStr);
// 2) numbers:
const num = 5;
const newNum = num + 10;
console.log(num);
console.log(newNum);
// 3) boolean:
const bool = true;
const newBool = !bool;
console.log(bool);
console.log(newBool);
function closures:
1) A closures is a combination of a function and the lexical environment within
which that function was declared.
2) It allows a function to access variables from its outer (enclosing) scope
even after the outer function has finished executing.
function outer(){
let count = 0;
function increment(){
count++;
console.log(count);
}
return increment;
}
let closure = outer();
closure();
closure();
closure();
closure();
closure();
Function Expression:
Function expression define functions as values assigned to variables. They are not
hoisted, so they can only be called after the variable assignment.
const hello = function (){
console.log("Hello Everyone");
}
hello();
//find the square of a number
// function declared inside the variable.
let a = function (num){
return num * num
};
console.log(a(5));
let b = a(8);
console.log(b);
*/

0 Comments