import React from 'react';
function QuirkyAgeGreeter(props) {
const { age } = props;
if (age < 18) {
return (
<div>
<h1>Hey there, little squirt!</h1>
<p>Welcome to the wacky world of React!</p>
</div>
);
} else {
return (
<div>
<h1>Greetings, esteemed individual.</h1>
<p>We're delighted to have you in our quirky React application.</p>
</div>
);
}
}
function App() {
return <div>
<QuirkyAgeGreeter age={12} />
<QuirkyAgeGreeter age={44} />
</div>
}
render(<App />)
body {
padding: 16px;
font-size: 24px;
}
h1 {
font-size: 32px;
}
console.log(undefined && "Boo")
console.log(8 && "Boo")
console.log(1 && "A" && 3 && 4)
console.log("Foo" && "Boo")
console.log(1 || "Boo")
console.log(0 || "Boo")
console.log("Foo" || "Boo")
console.log("A" || null && 0)
body {
padding: 16px;
font-size: 24px;
}
h1 {
font-size: 32px;
}
const App = () => {
return (
<ul>
<li><b>true</b>: {true}</li>
<li><b>false:</b> {false}</li>
<li><b>null:</b> {null}</li>
<li><b>undefined:</b> {undefined}</li>
<li><b>0:</b> {0}</li>
<li><b>NaN:</b> {NaN}</li>
<li><b>[]</b>: {[]}</li>
<li><b>[1, "a", 3]</b>: {[1, "a", 3]}</li>
</ul>
);
};
render(<App />)
body {
padding: 16px;
font-size: 24px;
}
h1 {
font-size: 32px;
}
ul {
padding-left: 32px;
}
import React from 'react';
function UserProfile({ userName, userBio }) {
const displayName = userName ?? 'Anonymous';
const displayBio = userBio ?? 'No bio available';
return (
<div>
<h1>Welcome, {displayName}!</h1>
<p>{displayBio}</p>
</div>
);
}
// Usage
function App() {
return (
<div>
<UserProfile
userName={undefined}
userBio={null}
/>
<UserProfile
userName="Tomas"
userBio="Jedi Forever"
/>
</div>
)
}
render(<App />)
body {
padding: 16px;
font-size: 24px;
}
h1 {
font-size: 32px;
}
console.log(true ? "Valeria" : "Tomas")
const a = 1000;
console.log(a < 500 ? "Profit" : "Loss")
body {
padding: 16px;
font-size: 24px;
}
h1 {
font-size: 32px;
}
import React from 'react';
function UserProfile({ name, bio, age }) {
return (
<div>
<h1>
{ age < 18 ? 'Yo, ': 'Welcome, ' }
{
name
? name
: <span style={{ color: 'red' }}>
No User Name
</span>
}!
</h1>
<p>{
bio
? bio
: 'No bio available' }</p>
</div>
);
}
// Usage
function App() {
return (
<>
<UserProfile
name="Tomas"
bio={null}
age={6}
/>
<hr />
<UserProfile
name={null}
bio="Invisible man"
age={44}
/>
</>
)
}
render(<App />)
body {
padding: 16px;
font-size: 24px;
}
h1 {
font-size: 32px;
}
console.log(null || "Tomas")
console.log(null && "Tomas")
console.log("Valeria" && "Tomas")
console.log("A" && "B" && "C")
console.log(null || false || "Tomas")
body {
padding: 16px;
font-size: 24px;
}
h1 {
font-size: 32px;
}
import React from 'react';
function UserProfile({ userName, userBio, userAge }) {
return (
<div>
<h1>
{ userAge < 18 ? 'Yo, ': 'Welcome, ' }
{ userName || <span>[missing name]</span>}
</h1>
{ userBio && <p>{userBio}</p> }
</div>
);
}
function App() {
return <>
<UserProfile userName={undefined} userBio={null} userAge={6} />
<hr />
<UserProfile userName="Tomas" userBio="Still Jedi" userAge={44} />
</>
}
render(<App />)
body {
padding: 16px;
font-size: 24px;
}
h1 {
font-size: 32px;
}
span {
color: red;
}