Intro to JavaScript

Javascript

What is JavaScript?

JavaScript is a scripting OR programming language that allows you to implement complex features on web pages, since most web pages do more than just sit there and display static information for you to look at. -MDN

What can JavaScript be used for?

Backend Database creation

Here is an example of a blog Post object that contains 2 required fields

const mongoose = require("mongoose");

module.exports = mongoose.model(
  "Post",
  mongoose.Schema({
    title: { type: String, required: true },
    content: { type: String, required: true }
  })
);

And here is the api to retrieve those posts or post

const express = require("express");
const router = express.Router();
const Post = require("../models/Post");

router.get("/", (req, res) => {
  Post.find({}, (error, data) => {
    if (error) return res.sendStatus(500).json(error);
    return res.json(data);
  });
});

router.get("/:postId", (req, res) => {
  Post.findById(req.params.postId, (error, data) => {
    if (error) return res.sendStatus(500).json(error);
    return res.json(data);
  });
});

Client side interactions (Frontend)

This is what we will be doing in our bootcamp since our tech stack uses Java and Spring to handle the backend api creation instead of JavaScript, MongoDB and Express.

  • DOM Manipulation
  • Fetching API data from the backend database and display it to the client on the frontend
  • Dynamically interact with the database to call the backend api methods to add/remove/change information displayed on the front end

Note all of this will need to have an ENTRY point into the pages we see on the frontend, through our HTML...this is why it is called a scripting language.

What are the 2 pillars of JavaScript?

  • Prototypal Inheritance (Objects without classes, Objects Linking to Other Objects)
  • Functional Programming (lambdas, closures)