Starting a new month with JavaScript

Eduardo Ahumada
6 min readAug 16, 2021

--

This last week marked the end of a phase where I focused my efforts directly on learning and getting experience in solving difficult problems to be prepared for a coding interview. I shared with you a lot of resources, exercises, and code that I worked on to practice. This preparation will not stop here, I’m going to keep solving problems and practicing more data structures and algorithms to stay prepared for any possible opportunities.

As part of my preparation, I'm still sharpening my skills and I have been restudying the basics of JavaScript. JavaScript is a very popular and fun programming language for web development, I would like to share with you the basics of it just in theory so you can learn about it and be aware of the aspects that differentiate this language from others. I would also like to talk about other things that I studied, such as interview preparation tools.

The very basics

Photo by Mohammad Rahmani on Unsplash

JS is a programming language that powers the dynamic behavior that we see on websites. Along with HTML and CSS, it is a core technology for web development.

In JavaScript we can:

  • 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. (+=, -=, *=, /=).

More old features to work with JS and others that were later introduced in versions like ES6 are:

  • 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

Besides reading and learning JS, I also learned about how to have successful interviews. This can be applied in general or to coding interviews. I learned about the importance of practice, gathering information, networking, research about everything, the things that one needs to know about the process (interviewer, enterprise, role, etc), how to create a successful elevator pitch, the relevance of thinking correctly about your strengths and weaknesses, how to create appropriate responses depending on the type of questions and many things more.

That would be all for this week, have a great day and see you in the next post.

Photo by Manuel Cosentino on Unsplash

--

--

Eduardo Ahumada

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