Building Career Without Degree
1 May 2024
const numbers = [1, 2, 3];
const [first, second, third] = numbers;
console.log(first);
console.log(second);
console.log(third);
const person = {
name: 'John Doe',
age: 30,
job: 'Developer'
};
const { name, age, job } = person;
console.log(name);
console.log(age);
console.log(job);
const UserProfile = ({ name, age, job }) => {
return (
<div>
<h1>{name}</h1>
<p>Age: {age}</p>
<p>Job: {job}</p>
</div>
);
};
// Usage
<UserProfile name="Jane Doe" age={28} job="Designer" />
useState
, destructuring the array returned by the hook is a common practice:import React, { useState } from 'react';
const Counter = () => {
const [count, setCount] = useState(0);
return (
<div>
<p>Count: {count}</p>
<button onClick={() => setCount(count + 1)}>Increment</button>
</div>
);
};
export default Counter;
const user = {
name: 'John Doe',
address: {
city: 'New York',
country: 'USA'
},
hobbies: ['reading', 'traveling', 'coding']
};
const {
name,
address: { city, country },
hobbies: [firstHobby]
} = user;
console.log(name);
console.log(city);
console.log(country);
console.log(firstHobby);
const Product = ({ title, price, description }) => {
return (
<div>
<h2>{title}</h2>
<p>Price: ${price}</p>
<p>{description}</p>
</div>
);
};
// Usage
<Product title="Laptop" price={999.99} description="A high-performance laptop" />