{
  "$type": "site.standard.document",
  "bskyPostRef": {
    "cid": "bafyreiaagl4mezqmvn5soii6y7bhlx6ww5krqja7weft4cvuldfoxdhwvq",
    "uri": "at://did:plc:dcwuu5uoeqs7kp75szpfxza6/app.bsky.feed.post/3lbfk67vfbd32"
  },
  "path": "/blog/js-crash-course/",
  "publishedAt": "2026-04-25T08:14:00.750Z",
  "site": "https://www.lion-byte.com",
  "tags": [
    "DevDocs - JavaScript",
    "Learn ES2015",
    "The Modern JavaScript Tutorial",
    "Node for Java Developers",
    "What is Node.JS for Java Developers",
    "Using a package.json"
  ],
  "textContent": "I wrote most of this post roughly a year ago for my Design Studio team, since some of our team members have not used JavaScript before. This is only meant to be a starting point in learning JavaScript.\n\n* * *\n\n## JavaScript Syntax\n\nJavaScript is a loosely-typed language. Instead of using `int`, `boolean`, etc., to initialize a variable, `var`, `let`, and `const` are used instead.\n\n### Variable Initialization\n\nNote: We will use only `let` and `const`.\n\n\n    // Cannot assign another value to this variable\n    const isEclipseFunky = true\n\n    let age = 12\n    let name = 'Tony'\n\n    // This is a plain object.\n    let allStar = {\n      some: 'body',\n      once: 'told me'\n    }\n\n    // List of numbers\n    let numberList = [1, 24, 25.01, 6, 0]\n\n    // Can hold mixed different types of data\n    let mixedList = [\n      \"I'm a string using double-quotes\",\n      'I am a string using single-quotes',\n      `I'm a string using backticks`,\n      12,\n      false\n    ]\n\n### Functions\n\nFunctions in JavaScript are a bit more flexible here. They can be assigned to variables and arguments to other functions.\n\n\n    const addNums = (a, b) => {\n      return a + b\n    }\n\n    let addResult = addNums(1, 2) // 3\n\n    // Using a function as an input\n    // It will use the callbackFunction input within the function.\n    // Many APIs and libraries do this\n    function multiplyNums(a, b, callbackFunction) {\n      const result = a * b\n      callbackFunction(result)\n    }\n\n    // Note: The function is unnamed. It's fine if we only use it once.\n    multiplyNums(2, 12, function (answer) {\n      console.log(answer) // 24\n    })\n\n    // Alternatively, we can write it like this:\n    multiplyNums(15, 3, answer => {\n      console.log(answer) // 45\n    })\n\n### Classes\n\n\n    class Person {\n      constructor(name, age) {\n        this.name = name\n        this.age = age\n      }\n\n      // This is a method\n      introduce() {\n        console.log(`My name is ${this.name}. I am ${this.age} years old.`)\n      }\n    }\n\n    // New instance of Person class\n    let p1 = new Person('Marty', 15)\n    p1.introduce() // console reads: 'My name is Marty. I am 15 years old.'\n\n    // You can extend classes as well\n    class Student extends Person {\n      constructor(name, age, id) {\n        super(name, age)\n        this.id = id\n      }\n\n      showId() {\n        console.log(this.id)\n      }\n\n      // `introduce ()` still exists\n    }\n\n## Modules\n\nYou can have functions, classes, and constants `export`ed from one file and `require`d / `import`ed in another.\n\nLet's have a simple example. Assume that both files are in the same directory.\n\n### Exporting\n\n\n    // `math.js`\n\n    const addNums = (a, b) => {\n      return a + b\n    }\n\n    function multiplyNums(a, b) {\n      return a * b\n    }\n\n    // (1) Here's where we export the functions\n    module.exports = {\n      addNums: addNums,\n      multiplyNums: multiplyNums\n    }\n\n    // (2) Note: if the property name and variable names are the same\n    // like in the lines above, then it can be written as such:\n    module.exports = {\n      addNums,\n      multiplyNums\n    }\n\nFor JavaScript that is transpiled with `webpack`, `parcel`, or any other bundler, you can use the ES6 syntax for exporting.\n\n\n    // (3) Exporting as it is defined\n\n    export const addNums = (a, b) => {...}\n    export function multiplyNums(a, b) {...}\n\n### Requiring / Importing\n\n\n    // `index.js`\n\n    // This will import from `math.js` in the same directory\n    // (1) You can specify which functions, classes, or constants you want using this syntax. More on this in the links below\n    const { addNums, multiplyNums } = require('./math')\n\n    // (2) The other way is like this:\n    /*\n      const math = require('./math')\n      const addNums = math.addNums\n      const multiplyNums = math.multiplyNums\n    */\n\n    // (3) ES6 `import` syntax\n    /*\n      import { addNums, multiplyNums } from './math'\n    */\n\n    let addResult = addNums(2, 4) // 6\n    let multResult = multiplyNums(3, 7) // 21\n\nNote: `import` / `export` is not available in Node.js natively at this time. Only `module.exports` and `require()`.\n\nThere are other neat features to ES6 that you can learn in the resources linked below.\n\n* * *\n\n## Node.JS\n\nNode.js is a runtime environment that interprets JavaScript - similar to JVM for Java. Node.js lets a JavaScript program be organized into separate files/modules.\n\n### NPM\n\nNPM is _unofficially_ called the Node Package Manager. (Technically it's not an acronym according to the NPM team, but whatever.) This is used to manage JavaScript packages and projects.\n\n### package.json and package-lock.json\n\nNode.js projects, like any other project, will have to manage dependencies. They also need to be tested, built, etc. Luckily, the package.json file holds all the information listed above!\n\nThe important sections in that file are as follows:\n\n  * `name` - Project name\n  * `version` - Project version\n  * `description` - Project description\n  * `scripts` - Command-line scripts that are run. It's way better save the commands here than trying to memorize them. (Or have them forgotten, and no one can run anything.)\n  * `main` - Specifies the primary file where everything runs.\n  * `dependencies` - Holds list of required dependencies for the project\n  * `devDependencies` - Holds list of dependencies used only for development\n\n\n\nAll packages added to the project update the package-lock.json file. This file saves the specific versions and the dependencies' dependencies. This was added in version 5 of npm.\n\n### CLI Commands\n\nNPM uses the package.json file to run the commands below\n\n  * `npm install <package-name>` - adds package to `dependencies`\n  * `npm install -D <package-name>` - adds package to `devDependencies`\n  * `npm run <command>` - runs the appropriate script in the `scripts` section\n  * `npm start` - equivalent to `npm run start`\n  * `npm test` - equivalent to `npm run test`\n\n\n\n* * *\n\nHopefully this gives you a clear idea about JavaScript and Node.js. I'll update this post as needed in the future. Linked below are some other tutorials or resources that may be helpful to you.\n\n## More Info/Resources\n\n  * DevDocs - JavaScript\n  * Learn ES2015 (Note: ES6 and ES2015 are different names for the same thing.)\n  * The Modern JavaScript Tutorial\n  * Node for Java Developers\n  * What is Node.JS for Java Developers\n  * Using a package.json\n\n",
  "title": "JavaScript Crash Course",
  "updatedAt": "2018-07-10T00:00:00.000Z"
}