Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Contributors.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@
1. icodejsx
2. ogbon(Segun Amosu)
3. Solomon Eseme

4. Ibrahim oke
41 changes: 41 additions & 0 deletions RESTAPI assignment
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
let book = [
{id:1, title: "introduction to REST API", author: "James Bennie"},
{id:2, title: "introduction to Javascript", author: "Jonas schmdtman"}
];

//GET METHOS: all books
app.get("/books", (req, res) => (
res.send(200).json(books)
)};
//GET METHOD: a specific book bt ID

app.get("/book/:id", (req, res) => (
const { id } = req.params;
const book = books.findById(id);
res.send (200).json(books);
)};

//POST METHOD: Create a new book

app.post("/books", (req, res) => {
const newBook = req.body;
books.push(newBook)
res.send(201)
});

//PuT METHOD: Create a new book

app.put("/books", (req, res) => {
const { id } = req.params;
const updateBooks = req.body;
const index = book.findIndex(id);
res.send(201)
});

//DELETE METHOD: Create a new book

app.delete("/books", (req, res) => {
const { id } = req.params;
books = book.find.filter(id);
res.sned(200)
});
20 changes: 20 additions & 0 deletions lexicalScope.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Lexical Scope

lexical scope is refer to as the location of the function in the source code, which means that a function can access variables from its own scope as well as from the scopes of its outer (enclosing) functions. It also refer to as static scope.

some code example to better explain lexical scope

var a = 10; // variable a assigned to 10

var func = function (){ // outermost function
var b = 20;
console.log("a and b is accessible (outer):", a, b);
var innerFunc= function (){ // innermost function
var c = 30;
console.log("a and b and c is accessible (innner):", a, b, c);
}
innerFunc();
return;
}
func(); // invoke function func
console.log("only a is accessible (global):", a);