Add lab 8 content
This commit is contained in:
parent
9b42d0f42c
commit
0697a23f50
25
journal/_src/posts/2022-09-28-lab-eight.md
Normal file
25
journal/_src/posts/2022-09-28-lab-eight.md
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
Title: Lab Eight
|
||||||
|
Date: 2022-10-05T08:30:00
|
||||||
|
Tags: cs2163, lab, javascript, type-coercion, functions, modules
|
||||||
|
|
||||||
|
In this lab I learned the javascript basics
|
||||||
|
<!-- more -->
|
||||||
|
|
||||||
|
## Hello world
|
||||||
|
In javascript, the way to print things is using `console.log()`, you can use this for any printing.
|
||||||
|
|
||||||
|
## Translating racket expressions
|
||||||
|
Javascript has a much more "math" like syntax where things are evaluated like traditional math expressions. In javascript the arithmetic operators are not treated the same as the rest of the functions like math operators are in racket.
|
||||||
|
|
||||||
|
## Type coercion
|
||||||
|
Javascript has odd functionality using the `==` operator. The assumption of that all types can be converted to each other creates odd behavior like an empty string being equal to 0.
|
||||||
|
|
||||||
|
## Functions
|
||||||
|
In javascript the `=` operator is strictly for assignment, and not for the creating of new variables or constants. In javascript you must explicitly say `let`, `var`, or `const` and to give it a name before the assignment takes place.
|
||||||
|
|
||||||
|
The reason return is required in the explicit form of lambda functions is that it is creating a local function and binding it to that variable. This local function needs the full syntax that a typical function requires.
|
||||||
|
|
||||||
|
The arrow operator in javascript is a shorthand for making a lambda function. It simply removes the verboseness that traditional lambda functions in javascript have. An example is the lack of the function keyword, the return keyword, and the requirement of braces surrounding the function code.
|
||||||
|
|
||||||
|
## Modules
|
||||||
|
Javascript modules are loaded by creating an object from another javascript file and then executing the exported functions of that file from the dot (`.`) operator on that object.
|
Loading…
Reference in New Issue
Block a user