45 lines
955 B
JavaScript
45 lines
955 B
JavaScript
// Importing React (necessary if using JSX)
|
|
import React from "react";
|
|
|
|
// Example function using a regular function declaration
|
|
function multiply(x, y) {
|
|
return x * y;
|
|
}
|
|
|
|
// Example usage of a function
|
|
let result = multiply(4, 5);
|
|
console.log("The product is:", result); // Output: The product is: 20
|
|
|
|
// Example of a variable declared with let
|
|
let count = 0;
|
|
for (let i = 0; i < 5; i++) {
|
|
count += i;
|
|
}
|
|
|
|
console.log("The count is:", count); // Output: The count is: 10
|
|
|
|
// Example of a variable declared with let (instead of const)
|
|
let message = "This is a message";
|
|
console.log(message);
|
|
|
|
// Example of a React functional component
|
|
function Greeting({ name }) {
|
|
return (
|
|
<div>
|
|
<h1>Hello, {name}!</h1>
|
|
</div>
|
|
);
|
|
}
|
|
|
|
// Usage of the Greeting component
|
|
function App() {
|
|
return (
|
|
<div>
|
|
<Greeting name="Alice" />
|
|
</div>
|
|
);
|
|
}
|
|
|
|
// Export the App component for usage in other parts of the application
|
|
export default App;
|