32
loading...
This website collects cookies to deliver better user experience
.finally()
method is useful to execute any function that needs to be executed after a Promise has been resolved (whether successfully or not).getData()
.then((res) => {
setData(res.data);
})
.catch((err) => {
setError(err);
})
.finally(() => {
setIsLoading(false);
});
String
, Number
, Boolean
, null
, and undefined
.let string1 = 'hello world'
let string2 = string1
string2
is assigned the value of string1
, being hello world.string2
won't affect string1
.string2 = 'foor bar'
console.log(string1)
// 'hello world'
console.log(string2)
// 'foo bar'
Array
, Function
, or Object
a reference to the object in memory is assigned.let object1 = { name: 'Alan Grant' }
let object2 = object1
object2.name = 'John Wick'
console.log(object1)
// { name: 'John Wick' }
console.log(object2)
// { name: 'John Wick' }
function OuterFunction() {
let outerVariable = 1;
function InnerFunction() {
console.log(outerVariable);
}
return InnerFunction;
}
const innerFunc = OuterFunction();
innerFunc();
// 100
innerFunc()
, it can still access outerVariable
which is declared in OuterFunction()
. This is called Closure.2 * "3"
// 6
"12" / 4
// 3