Day 6/100 - neogcamp lecture 1 notes

December 02, 2021

Header Image

As I started with my #100DaysOfCodeChallenge, I realised how when I had initially started to learn webdev, it was very fast paced & I felt the need to go back to the basics. So I decided to start with neogcamp Level Zero lectures to strengthen my fundamentals.

I worked through Lecture 1 today and here’s my notes/takeaways from it.

What is the difference between parameters and arguments of a function?

Parameters: The variable names we use to represent the input values when defining a function.

Arguments : The values that are passed as inputs to a function when the function is called.

How do we read user input using JavaScript?

In the browser : Using the prompt() method.

  • The prompt method has 2 optional parameters a question and a default value.
  • It causes the browser to display a dialog box with the optional question and an input field.
  • Returns the value entered by user.

In a CLI application : Using the readline-sync npm library.

  • Imported into a js script as var readlineSync = require("readline-sync").
  • Faciliates reading text input from the command line with the readlineSync.question(query) method. The query parameter is the question displayed to prompt user input.

Other functions of ‘readline-sync’ library

  1. question -> Displays the query string prompting text input from user. Returns input text.
  2. keyInYN -> If input is ‘Y’ or ‘y’, returns true. For any other character input, returns false.
  3. keyInSelect -> keyInSelect(list, query) Options from the list parameter are displayed with 1-based indexing. Input between 1 to list length are accepted and the index of the list item is returned.
  4. keyIn -> Records character entered.
  5. promptCLLoop-> promptCLLoop(obj) Allows you to simulate an interactive shell interface. The input obj object contains commands as keys and values contain functions to be performed corresponding to those commands.

‘chalk’ package

This is a cool library that lets you style your terminal, make it pretty and colorful. It is fairly easy to use. While trying to import this in my js script, I learned that it cannot be imported using the require() syntax and the import syntax cannot be used in CommonJs. And so I actually learned for the first time what CommonJs is.

This stackoverflow discussion has a nice explanation of the differences between a CommonJs module and an ES6 module.

Also, here’s my repl of the lecture exercises. I had fun doing these.

These are my notes and learnings from the first lecture! Thanks for reading ✨


Profile picture

Written by Simran Makhija who lives and studies Computer Science in Indore, India. You should follow her on Twitter