You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
but if you are used the let so it will throw the error
name="Test";console.log("name: ",name);// Cannot access 'name' before initialization
name: Test;letname;
Strict Mode and writing the good code
strict mode is basically used for follow the proper way & discipline of the rules in JavaScript ex. You will not do the hoisting kind of things after usign the 'use strict'
How code is parsed and compiled in JavaScript and Deep Dive into the JavaScript Engine
our Java Script Code will work in Java Script Engine through below Image
Heap Memory is Persistent memory and Stack is temp memory
Object with the Function
constuser={name: "Darshit",subject: (subjectName)=>{return`My Name is ${user.name} and My subject is ${subjectName}`;},address: "Dev Ashish Sky",};console.log(user.subject("Competive coding"));
Arrow Function in JavaScript
Fat Arrow function give return statment functionality
constsum=(a,b)=>a+b;console.log("sum the value",sum);
Default Argument of the Expression
you will be used the default argument in function and variables
callBack Function is basically use when we call one function and calling one function through we perform the certain other operation so that time we used the callback
constcallMe1=(value,callback)=>{callback("Your Value");};constcallMe2=(name)=>{console.log("My Name is khan",name);};callMe1("Test",callMe2);
call and apply used in javaScript
The call() method is a predefined JavaScript method.
It can be used to invoke (call) a method with an owner object as an argument (parameter).
Interable -> means in human terms object when you can use for for-loops
Various Methods for Creating the Arrays in JavaScript
for array prespective mostly we use the Below Methods
const data = [1,2,3]; // more cleaner and perspective base more good
If you want to convert string into so that time this method so much helpful
ex.Array.from("hi!"); [O/P] ['h','i','!']
Splice and Slice in JavaScript
Splice
splice(start, deleteCount, item1)
start:
The index at which to start changing the array.
deleteCount:
An integer indicating the number of elements in the array to remove from start.
splice(start)
splice(start, deleteCount)
splice(start, deleteCount, item1)
splice(start, deleteCount, item1, item2, itemN)
const name = ["Gajjar", "Darshit", "Hasmukhbhai", "Hello"];
name.splice(1,0,"Good);
o/p: name => ["Gajjar","Good","Darshit","Hasmukhbhai","Hello"]
name.splice(1,1,"Good");
o/p: name => ["Gajjar", "Good", "Hasmukhbhai", "Hello"]
name.splice(1,1,"hello"); => First Character for replacing the string, Second one removing after that string
o/p: name => ["Gajjar", "hello"]
Splice basically used for different Application like to accept certain value in Array
name.splice(4);
console.log(name); // O/P :=> [ 'Hello', 'Name', 'Test', 'How Are You ?' ]
Slice
Slice Array basically Return the Brand New Copy of the Array
slice()
slice(start)
slice(start, end)
start:
Zero-based index at which to start extraction.
A negative index can be used, indicating an offset from the end of the sequence. slice(-2) extracts the last two elements in the sequence.
---------------------------------------------------------------------
end:
The index of the first element to exclude from the returned array.
slice extracts up to but not including end.
For example, slice(1,4) extracts the second element through the fourth element (elements indexed 1, 2, and 3).
This keyword basically responsible for who calling the function. which function you need to retun back the response
Note
An arrow function doesn’t have its own this value and the arguments object. Therefore, you should not use it as an event handler, a method of an object literal, a prototype method, or when you have a function that uses the arguments object
getter and Setter add one addtional level of security in Java Script
Practical schenario : In normal Obj you're able to update the object. but it caused problem when you want to give extra level of securtiy like you unable to set object key
so that time this Getter and setter concepts are very useful
constperson={bio: "very Humble and Punctual person",setname(value){//setterworklikekeyif(value.trim() === ""){this._name='DEFAULT';return;}this._name=value;},getname(){returnthis._name;//_basicallythisconversationprecedenceusedfortodisplayprivatevariablevariable}}person.name="darshit gajjar";console.log(person.name);//darshitgajjar
Without setter try to set the value so what Happen ?
If you do without setter it will throw the error
constperson={bio: "very Humble and Punctual person",getname(){returnthis._name;//_basicallythisconversationprecedenceusedfortodisplayprivatevariablevariable}}person.name="darshit gajjar";//uncaughtTypeError: cannotsetthepropertyconsole.log(person.name);
Java Script Advanced concepts like Object Oriented Programming
Static Method is Utility Function that are used to call method directly through class method
classPerson{staticname="Darshit";constructor(){}staticage(){return"Hi, I will touch 25 LPA package under 3 years";}}console.log(Person.age());
When to use Classes
Inheritance in Java Script :: Video No:16 :: Module 10,11 and 12
Work in Progress
###################################################################
#####################################################################
##################################################################
##########################################
More On Number and String
Generate the Random Number Between 1 to 10 programme
The startsWith() method determines whether a string begins with the characters of a specified string, returning true or false as appropriate.
conststr1='Saturday night plans';console.log(str1.startsWith('Sat'));//expectedoutput: trueconsole.log(str1.startsWith('at',2));//expectedoutput: false
Trim Method in JavaScript
The trim() method removes whitespace from both ends of a string and returns a new string, without modifying the original string
constchorus='Because I\'m happy. ';console.log(`Chorus lyrics for "Happy": ${chorus.repeat(27)}`);//expectedoutput: "Chorus lyrics for "Happy": Because I'm happy. Because I'm happy. Because I'm happy. Because I'm happy. Because I'm happy. Because I'm happy. Because I'm happy. Because I'm happy. Because I'm happy. Because I'm happy. Because I'm happy. Because I'm happy. Because I'm happy. Because I'm happy. Because I'm happy. Because I'm happy. Because I'm happy. Because I'm happy. Because I'm happy. Because I'm happy. Because I'm happy. Because I'm happy. Because I'm happy. Because I'm happy. Because I'm happy. Because I'm happy. Because I'm happy. "
Async Call, Working With CallBacks, Promises and Async and Await
JavaScript Engine Works As Single Thread
Blocking The Code & Event Loop Concept
How Event Loop and JS Engine Works When Asynchronous Code Call
Event Loop : Event Loop is Js Machanism it will check every time anything remaining in Code or Not. If It will there so it will pick and put in the Java Script Engine
when Any Browser Api Find Like setTimeOut or setInterval so it will go Java Script Engine and then After goes on the Browser API section so Browser Handle Async Manner.
But Js Engine not stop it's working still it will continue his process and add other function and it's code.all things goes to the
Message Queue Works like toDo kind of let say Any Asynchronous code or when stack full so remaining thing add in message queue. so once Java script Execution complete one by one it will execute.
And event loop has key role to doing this.
Promise in Async Code
Promise is nothing But the Object. That is Used to create the Async Kind Of code.
So wither Resolve or Reject so both the side are possible
Catch Block Follow The Order
We are not used Catch Block Anywhere Else
Ex. This is the Order We are follow when we are used the Catch
Problem of Above code Order (1) Execute if Any thing Wrong Happen in order (1). so that is goes to the catch block but problem is our order No (3) will not work but in this case it works.
Because After Catch As per our JavaScript behavirour it goes to order no (3) also.
And run that code so it happer our desired output
How Catch Structure Help The our Code
If you Want to not crash something or If you want to skip something
So this things is somuch Important
You will Also Use Multiple Catch Blocks
ex.
getFun().then(data=>{constmyName=`${data} Ye Hello`;returnmyName;}).catch(err=>err).then(afterSkip=>{constchangeTitle=`${afterSkip} whatsApp`;returnchangeTitle;}).catch(err=>{return`${err} e Hello Hows The going`;})
Deep Copies Issue In React & Object Copies in JavaScript
Promise Race Condition is used when You have multiple Promise and You want to consider the Fastest Promise so that time Promise Race is used.
Note: If Fastest Promise is Resolved so it will not care about the Other promise.it means one resolved and other is not resolved but still it not throw the Error