0% found this document useful (0 votes)
8 views8 pages

Ip Odd Pratical

The document contains various examples of JavaScript functions, including traditional, anonymous, and arrow functions, demonstrating their usage in both ES5 and ES6 syntax. It also includes a promise example using ES6, a simple Node.js server implementation, and React components showcasing both functional and class-based components, along with routing using React Router. Each section provides code snippets illustrating the concepts discussed.

Uploaded by

vinayak
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views8 pages

Ip Odd Pratical

The document contains various examples of JavaScript functions, including traditional, anonymous, and arrow functions, demonstrating their usage in both ES5 and ES6 syntax. It also includes a promise example using ES6, a simple Node.js server implementation, and React components showcasing both functional and class-based components, along with routing using React Router. Each section provides code snippets illustrating the concepts discussed.

Uploaded by

vinayak
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 8

Aim: Write a function using ES5 and ES6 with any example

<!DOCTYPE html>
<html>
<head>
<body>

<script>

////////////////////////////////////SIMPL
FUCTION///////////////////////////////////////////////////////////
//1
function test1()
{
return "1";
}
console.log(test1());
//2
function test2()
{
console.log("2")
}
test2();
//3
function test3(x, y = 1)
{
return x + y;
}
console.log (test3(2));
//4
function test4(x, y = 2)
{
console.log(x + y);
}
test4(2);

//////////////////////////////////////ANONYMOUS FUNCTION/////////////////////////////////////////as
//5
test5 = function()
{
return("5")
}
console.log(test5());
//6
test6 = function ()
{
console.log("6")
}
test6();

//7
test7 = function (x, y = 3)
{
console.log(x + y);
}
test7(4);
//8
test8 = function (x, y = 4)
{
console.log(x + y);
}
test8(4);

///////////////////////////////////ARROW
FUNCTION///////////////////////////////////////////////////////////////////////
//9
test9=()=>{
return "9";
}
console.log(test9());
//10
test10=()=>{
console.log( "10");
}
test10();
//11
test11=(x, y = 10)=>
{
console.log(x + y);
}
test11(1);
//12
test12=(x, y = 10)=>
{
return "x + y";
}
test11(2);

</script>
</body>
</head>
</html>

Aim: write promise program using ES6 with any


example
<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-
scale=1.0">
<title>promise_YASH</title>
</head>

<body>
<script>
var p = 92;
var t = new Promise((resolve, reject) => {
console.log("Loading ..........");
setTimeout(() => {
if (p > 60) {
resolve("It is resolved");
}
else {
reject("It is reject");
}
}, 2000);
}).then((result) => {
console.log(result);
}).catch((err) => {
console.log(err);
});
</script>
</body>
</html>

Write first program using node with part B

const http = require('http');

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


res.statusCode = 200;
res.setHeader('Content-Type', 'text/plain');

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


res.end('Home Page\n');
} else if (req.url === '/about') {
res.end('About Page\n');
} else {
res.statusCode = 404;
res.end('Page Not Found\n');
}
});

server.listen(3000, () => {
console.log('Server running at http://localhost:3000/');
});

Aim: write programme class and functional


component in react
////GreetingFunction.js////

import React from "react"


export default function NewFun() {
let check;

check = () => {

alert("Fill Username and Details")


}
return (
<>
<input type="buttton" value="submit" onClick={check}></input>
</>
)
}

/// GreetingClass.js///

import React from "react";

export default class NewClass extends React.Component {

render() {

return (
<>
Username: <input type="text" name="Username" />
< br />
Password:<input type="text" name="Password" />

</>
)
}
}

////App.js////

import React from 'react';


import GreetingClass from './GreetingClass';
import GreetingFunction from './GreetingFunction';

function App() {
return (
<div>
<GreetingClass />
<GreetingFunction />
</div>
);
}

export default App;


Aim: Write programme react router in react

// Home.js import React from


'react';
export default func on Home() {
return (
<div>
<h1>Home Page</h1>
<p>Welcome to the Home Page!</p>
</div>
);
}

// About.js import React from 'react';


export default func on About() { return (
<div>
<h1>About Page</h1>
<p>This is the About Page!</p>
</div>
);
}

// Contact.js import React from 'react';


export default func on Contact() { return (
<div>
<h1>Contact Page</h1>
<p>Reach out to us on the Contact Page!</p>
</div>
);
}
// app.js import './App.css'; import
React from 'react';
import { BrowserRouter as Router, Routes, Route, Link } from 'react-router-dom';
import Home from './Home'; import About from './About';
import Contact from './Contact';

func on App() { return (


<div className="App">
<header className="App-header">
<Router>
<div>
<nav>
<ul>
<li><Link to="/">Home</Link></li>
<li><Link to="/about">About</Link></li>
<li><Link
to="/contact">Contact</Link></li> </ul>
</nav>
<Routes>
<Route path="/" element={<Home />} />
<Route path="/about" element={<About />} />
<Route path="/contact" element={<Contact />} />
</Routes>
</div>
</Router>
</header>
</div>
);
}
export default App;

You might also like