# | Slice() Method | Splice() Method |
---|---|---|
1 | It doesn't modify the original array(immutable). | Modifies the original array(mutable). |
2 | Returns the subset of the original array. | Its returns the deleted elements as an array. |
3 | It is used to pick the element from the array. | It is used to insert or delete elements from an array. |
var emp = {
name: "John",
age: 19
};
# | Windows | Document |
---|---|---|
1 | The window of Javascript is a global object which holds variables, functions, locations, and history. | This also comes under the window and can be understood as the property of the window. |
2 | It is the representation of the user’s browser window and represents the content of the webpage. | It is the representation of any HTML document that is loaded on the browser. |
3 | Global objects, functions, and variables of JavaScript are part of the window object. | The HTML tags, elements, and their attributes are members of the Document. |
const welcome = () => {
console.log("welcome to Coder Lite");
};
var a;
var b= null;
Here a is undefined, and b is null.
function ninjas() {
var course = "Web Development"; // course is limited to ninjas because it is a local variable
}
function dev()
{
//dev cannot access the course variable because it is local to the ninjas() function
}
var course = "Web Development"; // It is a global variable
function ninjas() {
var getninjas = course;
}
function dev()
{
var getninjas = course;
}
// for Single line comments and
/* Multi
Line
Comment
*/
(function(){
let x="Ajay"
console.log(x) // Ajay
})();
Example 2 :
(function(a,b){
console.log(a+b) // 30
return a + b;
})(10,20);
Example 3 :
(function() {
var counter = 0;
function add(a, b) {
return a + b;
}
console.log(add(10,20)); // 30
}());
Example 4 :
(function() {
var counter = 0;
function add(a, b) {
return a + b;
}
console.log(add(10,20)); // 30
}());
Important Point
function myFunc()
{
console.log("Welcome to"); // Welcome to
// This will be executed after executing the previous log.
(function() {
console.log("Ajay Kumar"); // Ajay Kumar
})();
console.log("Hi There!"); // Hi There!
}
myFunc();
// Declaring the parameter required.
(function(dt) {
console.log(dt.toLocaleTimeString()); // 6:12:57 PM
// Passing the Parameter.
})(new Date());
var x = 5;
x = 10; // Allowed
let y = 5;
y = 10; // Allowed
const z = 5;
z = 10; // Error