Skip to main content

Posts

create a custom prototype in JavaScript

  * JavaScript implements inheritance by using objects. Each object has an internal link to another object called its prototype. * Prototypes are hidden objects that are used to share the properties and methods of a parent class to child classes. Live result:-  https://playcode.io/1943770 /* Find the age greater than 10 from an array of age */ var age = [ 10 , 11 , 2 , 1 , 20 ]; /*Solution 1 with .filter() function*/ let result = age . filter ( function ( a ){   return a > 10 }); console . log ( 'Age greater than 10 : ' , result ); /*Solution 2 using custom prototype method ' showAgeGreaterThan10' */ Array . prototype . showAgeGreaterThan10 = function () {   return (       age . filter ( function ( val ){       return val > 10     })  ) }; console . log ( 'Custom prototype :' , age . showAgeGreaterThan10 ());
Recent posts

shallow copy vs deep copy JavaScript

 In JavaScript, this is often achieved using methods like - Object.assign({}, originalObject) or  {...originalObject} Live result URL:-   https://playcode.io/1944513 //Deep and Shallow Copy in JavaScript //Example 1 let x = 'Hello world' ; let y = x ; console . log ( "x is : " , x ); console . log ( "y is : " , y ); //Example 2 let obj = {   name : 'Anil' } let obj1 = obj ; obj1 . name = 'Reena' ; console . log ( "obj is : " , obj ); console . log ( "obj1 is : " , obj1 ); //Example 3 let objA = {   name : 'Anil A' } let objB = Object . assign ({}, objA ); //Type 1: this is called a 'Shallow Copy'. It copies the memory location. Also, it copies only the main object. //OR let objB ={...objA} //Type 2: this is also called a 'Shallow Copy'. It copies the memory location. Also, it copies only the main object. objB . name = 'Reena B' ; console . log ( "objA is : " , objA ); c

Prototype Inheritance in JavaScript | Prototype chain in JavaScript

* Inheritance and the prototype chain - JavaScript.  * JavaScript implements inheritance by using objects. Each object has an internal link to another object called its prototype. * Prototypes are hidden objects that are used to share the properties and methods of a parent class to child classes. live result link:-  https://playcode.io/1943752 /* * Inheritance and the prototype chain - JavaScript.    * JavaScript implements inheritance by using objects. Each object has an internal link to another object called its prototype.    * Prototypes are hidden objects that are used to share the properties and methods of a parent class to child classes. */ var obj1 = {   id : 1 ,   name : "Anil" ,   isActive : true ,   age : 39 } var obj2 = {   address : 'Gaur City 2' ,   pin : 201306 ,   __proto__ : obj1 } console . log ( obj2 );

Closure in JavaScript | lexical scope | lexical scope vs closure

A closure gives you access to an outer function's scope from an inner function. A closure is a function having access to the parent scope, even after the parent function has closed. See the live result:-  https://playcode.io/1941383 //Clousure var sum = function ( a ){       console . log ( "Live Clousure views - " + a );       var c = 2 ;       return function ( b ){         return a + b + c; //lexical scope       } } //this function execute two times - one is - sum(1) and other one is - sumAgain(3) //the value of a=1 and c=3 will be presist in the mermory. One call to sumAgain(3) then the result will be 6 (1+3+2) //that is called closure   var sumAgain = sum ( 1 ); //calling and set the value of a=1 and c=2 in the memorey console . log ( sumAgain ( 3 )); //calling with value b=3. Now the result will be 6

JavaScript for-loop, forEach, Map, Filter and Sort Functions | forEach() .map(), .filter() .sort()

//Exploring for-loop, forEach, Map, Filter & Sort Functions //Write the code to get the array of names from the given array of users //pick only active users //sort users by age ascending Result URL link:  https://playcode.io/1943698 When you loop through (or iterate through) an array, the first thing you think of is probably a for loop,   .forEach() , .map(), and .filter() are all just other ways of iterating through arrays to perform a specific task on each array element and are called methods. //Exploring for-loop, forEach, Map, Filter & Sort Functions //Write the code to get the array of names from the given array of users //pick only active users //sort users by age ascending var users = [   { id : 1 , name : 'Anil' , isActive : true , city : 'Noida' , age : 39 },   { id : 2 , name : 'Alok' , isActive : true , city : 'GR Noida' , age : 40 },   { id : 3 , name : 'Sunil' , isActive : false , city : 'Delhi' , age : 29 },   {

The Evolution and Benefits of Using a 4G Mobile Proxy

In today's digital age, maintaining privacy and accessing content freely on the internet have become paramount concerns for both individuals and businesses. With the rise of sophisticated cyber threats and increasing online surveillance, the need for reliable and secure internet solutions is more pressing than ever. This is where a 4G mobile proxy comes into play, offering a unique blend of security, accessibility, and versatility. What is a 4G Mobile Proxy? A 4G mobile proxy is a type of proxy server that uses a mobile network to route internet traffic. Unlike traditional proxies that rely on data centers or residential IP addresses, a 4G mobile proxy leverages the IP addresses assigned by mobile carriers. This makes the proxy more resilient to detection and blocking by websites, as it mimics genuine user behavior more accurately. Advantages of Using a 4G Mobile Proxy 1.      Enhanced Anonymity and Privacy: By routing your internet traffic through a 4G mobile proxy, you ca

The Future of Mental Health: Developing Effective Mental Health Apps

The Future of Mental Health: Developing Effective Mental Health Apps  :- In recent years, the proliferation of smartphones and digital technology has opened new avenues for addressing mental health challenges. Among these innovations, mental health app development has emerged as a promising tool to provide accessible, affordable, and effective mental health support. This article delves into the intricacies of developing mental health apps, exploring their potential, the challenges involved, and best practices for creating impactful applications. The Promise of Mental Health Apps :- Mental health apps hold tremendous promise due to their accessibility and ability to reach a broad audience. They can provide immediate support, educational resources, and self-help tools, making mental health care more democratized. Key benefits include: 1.      Accessibility: Apps can reach users regardless of geographic location, breaking down barriers to traditional therapy such as stigma, cost, and