Starting a new month with JavaScript

The very basics

Photo by Mohammad Rahmani on Unsplash
  • We can log or print to the console using theconsole.log() method.
  • We can use strings with single and double-quotes.
  • It is possible to use numbers, which are a primitive data type including the set of all integers and floating-point numbers.
  • We can use booleans (true or false).
  • We can express an intentional absence of value using null.
  • It is possible to use the well-known arithmetic operators: addition, subtraction, multiplication, division, and modulo. (+, -, *, /, %).
  • In strings and arrays, for example, we can use the .length property, to know its size.
  • We have Methods that return information about an object and are called by appending an instance with a period, the method name, and parentheses.
  • When a new piece of data is introduced into a JavaScript program, the program keeps track of it in an instance of that data type. An instance is an individual case of a data type.
  • Libraries contain methods that can be called by appending the library name with a period ., the method name, and a set of parentheses.
  • We can create single-line comments using // and multi-line comments using /* … */.
  • We have the following assignment operators: addition assignment, subtraction assignment, multiplication assignment, division assignment. (+=, -=, *=, /=).
  • The use of string interpolation, which allows us to include the value of variables to construct strings used in the form text ${expression} text, and instead of using single or double quotes, we use back sticks ``.
  • Variables are used to store data, they can be created with the use of specific keywords that will change how we interact with them. Undefined is a primitive JavaScript value that represents a lack of defined value. Variables that are declared but not initialized to a value will have the value undefined.
  • The var keyword is used in pre-ES6 versions of JavaScript. You can redeclare and reassign variables that use this keyword within the same scope (which can be problematic).
  • The let keyword is the preferred way to declare a variable when it can be reassigned. You cannot redeclare a variable with this keyword within the same scope. Initialization is optional and it will have a value of undefined if not initialized.
  • The const keyword is the preferred way to declare a variable with a constant value. Initialization is required. Any attempt of re-assigning a const variable will result in a runtime error.

Conditionals

Control flow is the order in which statements are executed in a program. Conditionals are used to alter the control flow.

  • We can use the if-else conditional, then we have the if-else if conditional that can finish in an else.
  • We can also use a switch statement, that allows us to check different values in a variable and do something depending on that value through cases. Every case should use a break statement to stop the program from running the next cases. We also have a default option.
  • A unique way of using conditionals is with the use of ternary operators which is a way of implementing binary conditionals. It accepts a condition followed by a ? operator, and then two expressions separated by a : . If the condition evaluates to truthy, the first expression is executed, otherwise, the second expression is executed.
  • We have logical operators such as && (and) and || (or), and ! (not).
  • In JavaScript, values evaluate to true or false when evaluated as Booleans.
  • Values that evaluate to true are known as truthy.
  • Values that evaluate to false are known as falsy.
  • Falsy values include false, 0, empty strings, null, undefined, and NaN. All other values are truthy.
  • For the comparison operators we have: strict equal (===) for matching value and data type, strict not equal (!==), less than (<), less than or equal (<=), greater than (>), and greater than or equal (>=).

Functions

  • One unique way of creating functions in JS is through arrow functions.
  • The syntax for an arrow function expression does not require the function keyword and uses a fat arrow => to separate the parameter(s) from the body.
  • There are several variations of arrow functions: Arrow functions with a single parameter do not require () around the parameter list. Arrow functions with a single expression can use the concise function body which returns the result of the expression without the return keyword.
  • Functions can be created using the function keyword followed by the name, and parenthesis.
  • We can also create functions as anonymous functions, they can be defined using the function keyword and assigning the implementation to a const variable. Like const anon_funct = function() {…}.
  • Function expressions create functions inside an expression instead of as a function declaration. They can be anonymous and/or assigned to a variable.
  • Remember parameters are kind of placeholders of the values that a function expects. The values that we send when calling a function are called arguments.

Scope

With scope, we refer to the space where values and functions can be accessed.

  • Elements in the Global scope can be accessed from anywhere in the program.
  • In Function scope, values and functions are only visible from within the function.
  • In Code block scope, values and functions are only visible within { … } codeblock.

More topics to read

Other topics that I have been studying in order to enhance my skills with this programming language are:

  • Arrays
  • Loops
  • Iterators
  • Objects
  • Classes
  • Browser compatibility
  • Modules
  • Promises
  • Async-Await
  • Requests
  • “This” keyword
  • Hoisting
  • Event loop

Other things that I learned about

Photo by Maranda Vandergriff on Unsplash
Photo by Manuel Cosentino on Unsplash

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Eduardo Ahumada

Eduardo Ahumada

Engineer looking to help and contribute. Learning about Software development and Computer Science.