Lambda School Pre-course 7: Learn what JavaScript is and be able to explain its uses in web development

There are nine units in Lambda School’s Full Stack Web Development Pre-course. I’m going to summarize what the pre-course covers for each of them. This material is basically ground-floor information that students need to know before they start the full course.

precourse7

Learn what JavaScript is and be able to explain its uses in web development

With the basics of HTML and CSS covered, we move on to JavaScript, the language that enables interactivity in web pages. HTML and CSS handle displaying content. JavaScript allows web pages and web applications to accept user input and act on it. That’s really the big difference between markup and programming. There are some people who split hairs and differentiate between scripting and programming. The main difference seems to be that scripting languages aren’t generally compiled into machine language or turned into executable files. They’re run and interpreted on-the-fly. Programming languages have to be compiled and turned into 0’s and 1’s before they can be run – and are generally turned into executable files.

What is JavaScript and why do we use it?

As stated earlier, JavaScript is a programming language that was developed to add interactivity and functionality to websites. It was developed in 1994 and was intended to be a front end technology for web developers. Originally, it only ran in web browsers, but in 2008, Google developed the “V8 engine” which improved its functionality and speed. This, in turn, led to the creation of new front end frameworks and to the release of Node.js, a technology which allows JavaScript to run on the back end, or on servers. Essentially, it can now be used to write applications that are not confined to the browser.

As per the Lambda School text:

We can find JavaScript used on the front end, back end, mobile, Internet of Things (Iot), game development, and really anywhere a traditional programming language would be used. Recently, the newest version of the JavaScript language was released, ES6*. We will be focusing on and using ES6 in this course, and in the full Lambda School CS course.

*even newer versions have come out (ES7, ES8, etc) but this release is where a major paradigm shift happened. We will be referring to any concepts released after ES6, to simply ES6.

ES6, or ECMAScript/ECMAScript 2015 is a standard, and JavaScript is an implementation of that standard. Apparently, the name ES6 can be used interchangeably with JavaScript, and the version of JavaScript which supports it is also called JavaScript 6.

JavaScript vs Java (and other languages)

JavaScript and Java are not the same language. They’re actually not even directly related to each other. The name was essentially a marketing ploy, meant to ride on the coattails of Java’s popularity. The language uses concepts from other programming languages, including Java and C, but also lesser-known ones like Self and Scheme.

Its also considered a ‘loosely’ typed language. This means that data types exist, but they are not strictly enforced. Types are essentially different kinds of data – some types are alphanumeric (containing letters, numbers and symbols), some only contain numbers (or certain kinds of numbers – generally either with or without decimals), and others hold information like “True/False”. (I don’t quite understand the significance of loosely-typed languages vs. those which strictly enforce type, but I’m sure it will be revealed with time.)

How to ‘run’ JavaScript

JavaScript can apparently be typed in a browser via a console that’s built into many browsers (F12 in Chrome). This isn’t the most common way of running it, however. Most JavaScript is saved to files with the .js extension, loaded by a browser and run from there. The browser generally loads JavaScript code when an HTML tag on a web page calls for a .js file to be loaded and run.

Node.js additionally allows JavaScript to be executed from a server via the command line, now. So, applications can be written using JavaScript and run outside of a web browser using Node.js as its launching point.

As per the Lambda School text:

For this class, we are going to use a special code sandbox program just like we did with the last lesson (CodePen), called repl.it. This will allow us to write and edit our code and run it right in our browser window to see a real-time read-out.

I’m unsure why we’re using repl.it to learn JavaScript, instead of continuing in CodePen, which also supports JavaScript. I joined the Slack channel for the class last night, so I might inquire there and see if I get an answer.

Variables

Variables are essentially containers that hold information. Usually, they hold only a specific kind of information, so when they’re created, they have to have a name and a type assigned to them. This identifies the variable and then defines what kind of data it can hold. If a program asks a user for his/her name, that information is stored in a variable for later use. If a user chooses a payment method when shopping online, that payment method is stored in a variable for later use. Essentially, anything that gathers information or allows choice or branching is usually a variable, and the information in a variable can change. Names can be misspelled and then corrected (and passwords, as most people come to learn), the total cost of an item from an online store can change, based on discounts, shipping cost and tax. All of these pieces of information are saved in variables.

As per the Lambda School text:

At the heart of JavaScript are variables. A variable is a way to store the value of something to use later. (A note for those with previous programming knowledge: JavaScript is a loosely-typed language, which means that a variable can be set (and reset) to any type. We do not need to declare its type when initiating the variable.)

The anatomy of a variable is first the keyword, a space, the name we are giving the variable, an equal sign, the value we are assigning the variable, and then a semicolon.

There are three ways to declare a variable. Declaring a variable creates it in a program by giving it a name, usually a data type, and very often a starting value. Until a variable is declared, it doesn’t exist.

var firstName = 'John';
let lastName = 'Wick';
const favoriteFood = 'steak';
  • Var is a statement used to declare a variable. It existed before ES6 was created, and is thought of as the ES5 (or old) way of declaring variables. Variables declared this was are global, which means they exist throughout the entire program.
  • Let is a new ES6 variable keyword. Its variables are block-limited. Let will assign a variable like var, but that variable only exists in the block of code in which it was created – often this is a loop, or some other chunk of code. Variables declared using let don’t exist outside of the block of code that they were declared in, so they can’t be used outside of it.
  • Const is also new in ES6. A const is a variable that cannot be changed. It’s short for “constant”. Its used in a lot of other programming languages. In our software, something like our clients’ company name and address would be a constant.

Primitive Data Types (String, Number, Boolean)

As per the Lambda School text:

The term ‘primitive data type’ refers to the fact that these are the most basic data types in the language. All other data types (which we will learn about in later lessons) use these types.

  • Strings are blocks of text. They are defined with quotation marks around them, either single or double. Any text with quotes around it is a string. (const dog = ‘fido’;)
  • Numbers are numeric data. They do NOT have quotes around them and can be negative. (const answer = 42;) (const negative = -13;)
  • Booleans are binary variables and can have only 1 of 2 values: on or off, 0 or 1, true or false. In JavaScript, Booleans mean true or false and are used for logical branches or conditions. (const baconisafoodgroup = true;)

One thought on “Lambda School Pre-course 7: Learn what JavaScript is and be able to explain its uses in web development

Leave a comment