Skip to content

Instantly share code, notes, and snippets.

@ross-u
Last active October 13, 2020 13:32
Show Gist options
  • Save ross-u/9e4c608631ddc4342edb0036bb3ed2c7 to your computer and use it in GitHub Desktop.
Save ross-u/9e4c608631ddc4342edb0036bb3ed2c7 to your computer and use it in GitHub Desktop.
JavaScript Introduction

JavaScript Introduction

What is JavaScript

  • JavaScript is a lightweight compiled programming language with the first-class functions.

  • JavaScript was created to run in the browser (mostly used for the Web), however it is also used in non-browser environments: Node.js (server side) and Electron (desktop applications).


ECMAScript

  • ECMAScript is the standard for JavaScript and its implementation.

  • The most recent versions of ECMAScript (shorter ES) that are currently being used are :

    ES5 (from 2009.), ES6 (from 2015.), ES7 (2016.)

  • JavaScript never removes old features – new versions are always backward compatible, meaning that new versions of the language include old features and new features can be converted to the legacy code.


Syntax

  • Parentheses () and curly braces {} are mandatory and will cause an error if they’re left out, with few exceptions.
  • JavaScript does not strictly require semicolons ; , however we use them always to prevent possible errors.

Variables and data types

  • Variable is a named container or a storage for data in the memory.

  • Variable can be declared with keyword var or let or const.

  • Different values (known as data types) can be stored in variables : string, *number, array, object, function, boolean, etc.

// Objects
var myArray = [];
var myObject = {};

// Primitives
var myString = "Uros";
var myNumber = 100;
var myBoolean = true; // true or false
var myNull = null;
var myUndefined = undefined;

// We won't use the below data types
var mySymbol = Symbol();
var myBigInt = 9007199254740991n; 

Declaring and Assigning

  • Declaring simply means “saving a spot in a memory” without assigning any value to it.
var a;
  • Assigning means storing the value in a variable, using the = operator.
a = 10;
  • We can declare a variable and assign the value on the same line.
var user = 'Sarah';

Variable naming rules:

  • In JS variable names can contain letters (uppercase and lowercase), numbers and the symbols _and $.

  • In JS the first character of the variable name cannot be a number.


Correct naming and style guide

  • Write variable names that are easily understandable and human readable. Don't one letter names, you are better than that :) !

  • Name variables as descriptive and concise as possible (examples of good naming: userName, creditCardNo, and examples of bad names: info, value, etc.)

  • camelCase notation is the common convention when naming variables.

  • As a common style guide during the bootcamp we will be using single quotes in Javascript ''.

  • When writing code use 2 spaces indentation (set 2 spaces indentation in your editor ).


Reserved keywords

  • Keywords are tokens that have special meaning in JavaScript and cannot be used as variable names. Most common ones are: var, function, return, let, const, typeof, new, for , etc. ...

Dynamically typed

  • JavaScript is a dynamically typed language which means that new variables can be created during the runtime, and the type of variables is determined at runtime.
  • Simply put variables can be reassigned different value of a different types at runtime.

typeof operator

🔖 typeof is JavaScript operator that returns the type of the variable we passed to it. You can read more about it here.

var myVar = "IronHack";
console.log(typeof myVar);

myVar = 100; // We reassing a new value of a different type to myVar
console.log(typeof myVar);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment