You are on page 1of 4

ASSIGNMENT

SUBMITTED BY: JALAJ JASWAL


E.NO: 9921102029
BATCH: E1

QUESTION-1:
import { useState } from 'react';

export default function Counter() {


const [counter, setCounter] = useState(5);

return (
<>
<span>{counter}</span>
<button onClick={() => {
setCounter(counter + 5);
setCounter(counter + 5);
alert(counter);
setCounter(counter + 5);
setCounter(counter + 5);
}}>Increment</button>
</>
)
}

OUTPUT OF THIS CODE WOULD BE ALERT WITH 5,10.

QUESTION: 2
import { useState } from 'react';

export default function Counter() {


const [counter, setCounter] = useState(5);

return (
<>
<span>{counter}</span>
<button onClick={() => {
setCounter(counter => counter + 5);
setCounter(counter => counter + 5);
alert(counter);
setCounter(counter => counter + 5);
setCounter(counter => counter + 5);
}}>Increment</button>
</>
)
}

OUTPUT OF THIS CODE WOULD BE ALERT WITH 5,25.


QUESTION: What are props in react?
Props are input to a react component. They are single values or objects containing a set of
values that are passed to react component on creation using a naming convention similar to
HTML-tag attributes. i.e, they are data passed down from a parent component to a child
component.
The primarily purpose of props in react is to provide following component functionality:
1. Pass custom data to your react component.
2. Trigger state changes.
3. Use via this.props.reactProp inside component’s render() method.

QUESTION: 1 : CREATING YOUR OWN SERVER USING NODEJS


Index.js file
const http = require('http')

const server = http.createServer((req, res) => {


res.end('request granted');
})

server.listen(80, '127.0.0.1', () => {


console.log('Listening on port 80');
})

Router.js file
const http = require('http');

const server = http.createServer((req, res) => {

if (req.url == '/') {
res.end('This is HomePage');
}
else if (req.url == '/about') {
res.end('This is About Page');
}

else if (req.url == '/contact') {


res.end('This is Contact page');
}

else {
res.writeHead(404, { 'content-type': 'text/html' });

res.end('404 Page Not Found');


}

});

server.listen(80, '127.0.0.1', () => {


console.log('Listening on port 80');
});

QUESTION: 2 : CREATING AND EXPORTING THE MODULES


Index.js file
const {add, sub, mul} = require('./operation')

console.log(add(5,5))
console.log(sub(5,5))
console.log(mul(5,5))

operation.js file
const add = (a, b)=>{
return a + b;
}

const sub = (a, b)=>{


return a - b;
}

const mul = (a, b)=>{


return a * b;
}

module.exports = {
add,
sub,
mul
}

QUESTION: 1: WHAT IS NODEJS?


Node.js is a very popular scripting language that is primarily used for server-side
scripting requirements. It has numerous benefits compared to other server-side
programming languages out there, the most noteworthy one being the non-blocking
I/O.

WORKING OF NODEJS:

Node.js is an entity that runs in a virtual environment, using JavaScript as the primary
scripting language. It uses a simple V8 environment to run on, which helps in the
provision of features like the non-blocking I/O and a single-threaded event loop.

You might also like