Javascript Training 2026

From bibbleWiki
Revision as of 22:22, 24 May 2026 by Iwiseman (talk | contribs)
Jump to navigation Jump to search

Introduction

Never thought I would be doing this. Love typescript and this will be a challenge but doing more with less is fun too. So on here will be the bits I never knew about JS

Node

commonJS module.exports = require. And although import works for a function, it does not work for a class so you have to use it
ESM export = import

So never made a package outside of using npm so this was a surprise. Make a folder fun_m and add package.json

{
  "name" : "myModule",
  "main" : "./stimpy.js"
}

You put your file stimpy.js in the same directory

module.exports = {
  speak: function() {
    return "happy, happy, joy, joy";
  }
};

So in your main you can import the folder

const fun = require('./fun_m');

console.log(fun.speak());

arguments

Well this was a stunner. First what does this return

function add(x, y) {
  return(x + y);
}
console.log(add(1, 2, 3, 4, 10, 20));

It ignores the extra arguments and print 3

function args () {
  return arguments;
}
console.log(args(8, 7, 6, 5, 4));

Well turns out arguments is a keyword in js and it prints [8, 7, 6, 5, 4]