function Car() {
this.make = 'Lamborghini';
return { make: 'Maserati' };
}
const myCar = new Car();
console.log(myCar.make);ββββββ
#JavaScript #Quiz
Please open Telegram to view this post
VIEW IN TELEGRAM
π€―10π9β€4
Promise.all and Promise.allSettled are two methods provided by JavaScript's Promise API, but they have different behaviors and use cases.Waits for all promises to resolve or rejects immediately if any promise rejects. Resolves with an array of resolved values.
Waits for all promises to settle (resolve or reject) and always resolves. Returns an array of objects representing the outcomes of the promises, including their status and value/reason.
ββββββ
ββββββ
#JavaScript
Please open Telegram to view this post
VIEW IN TELEGRAM
β€8π3
num?const num = parseInt('7*6', 10);For example, in "78", only "7" is valid, so it parses it into the decimal 7, ignoring the "" and "8". Thus, num now equals 7.
ββββββ
#JavaScript #Quiz
Please open Telegram to view this post
VIEW IN TELEGRAM
π8π€―5
import { useState } from 'react';
function Counter() {
const [count, setCount] = useState(0);
return (
<div>
<p>You clicked {count} times</p>
<button onClick={() => setCount(count + 1)}>Click me</button>
</div>
);
}import { useRef } from 'react';
function InputFocus() {
const inputRef = useRef(null);
function handleFocus() {
inputRef.current.focus();
}
return (
<div>
<input ref={inputRef} />
<button onClick={handleFocus}>Focus Input</button>
</div>
);
}- State is immutable
- Avoid reading/writing refs during rendering
- Both persist data and have different update behaviors
ββββββ
ββββββ
#JavaScript #ReactJS
Please open Telegram to view this post
VIEW IN TELEGRAM
π11π1
const user = {
email: "[email protected]",
updateEmail: email => {
this.email = email;
}
}
user.updateEmail("[email protected]")
console.log(user.email)[email protected][email protected]ββββββ
#JavaScript #Quiz
Please open Telegram to view this post
VIEW IN TELEGRAM
π9π€―5β€4
const box = { x: 10, y: 20 };
Object.freeze(box);
const shape = box;
shape.x = 100;
console.log(shape);
ReferenceErrorObject.freeze prevents adding, removing, or modifying properties of an object (unless the propertyβs value is another object).
When we create the variable shape and set it equal to the frozen object box, shape also refers to a frozen object. You can check if an object is frozen using Object.isFrozen. In this case, Object.isFrozen(shape) returns true.
Since shape is frozen and x is not an object, we cannot modify x. Therefore, x remains 10, and { x: 10, y: 20 } gets logged.
ββββββ
#JavaScript #Quiz
Please open Telegram to view this post
VIEW IN TELEGRAM
π16π2π€―1
<div onclick="console.log('first div')">
<div onclick="console.log('second div')">
<button onclick="console.log('button')">
Click!
</button>
</div>
</div>
The deepest nested element that caused the event is the target of the event. You can stop bubbling by event.stopPropagation
ββββββ
#JavaScript #Quiz
Please open Telegram to view this post
VIEW IN TELEGRAM
π€―5π4β€3
ββββββ
ββββββ
#JavaScript
Please open Telegram to view this post
VIEW IN TELEGRAM
π5
ββββββ
ββββββ
#javaScript #react
Please open Telegram to view this post
VIEW IN TELEGRAM
β€7π1
This media is not supported in your browser
VIEW IN TELEGRAM
// Inefficient: Repeatedly resizing the array
let arr = [];
for (let i = 0; i < 10000; i++) {
arr.push(i);
}
// Efficient: Using a pre-sized array
let arr2 = new Array(10000);
for (let i = 0; i < 10000; i++) {
arr2[i] = i;
}
ββββββ
ββββββ
#javaScript #performance #softwareEngineering
Please open Telegram to view this post
VIEW IN TELEGRAM
β€3π2
ββββββ
ββββββ
#JavaScript
Please open Telegram to view this post
VIEW IN TELEGRAM
β€13π5π1