1.7 KiB
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
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.