February 27th, 2018
Hello! Today at the ES6 course by Wes Bos I learned about maps and weak maps.
Maps are like objects. They have key-value pair. You can call .has() and .delete() on them.
As well as loop over them in two ways.
dogs.forEach((val, key) => console.log(val, key));
for(const [key, val] of dogs) {
console.log(key, val);
}
Map-metadata:
You can use an object as a key. You can store metadata about an object. Weak-map does not have a size, and it isn't innumerable. Items get garbage collected.
const weak = new WeakMap();
At the Web Development Bootcamp by Colt Steele I learned about the EJS Control Flow.
We have to wrap each JS line in the <% %> tags
<% if(thingVar.toLowerCase === 'Aaron') { %>
<p>GOOD CHOICE! </p>
<% } %>
You have to take away the equal signs because there are two different types of tags
<%= %> - the value that is returned will be rendered to the page, added to the HTML
<% %> - there is a logic, loops, control flows we don't want to add it to the page
Using a loop
app.get("/posts", function(req, res) {
var posts = [
{title: "Post 1", author: "Suzy"},
{title: "My adorable pet bunny", author: "Charlie"},
{title: "Can you believe pomsky ", author: "Colt"}
];
res.render("posts.ejs", {posts:posts});
});
Cheers!