YDKJS — Up & Going

Photo by Fabian Grohs on Unsplash

A primer on what JavaScript is and isn’t

Overview of basic JavaScript Concepts & Terminology

Statements

let a = b * 2;
  • a and b are variables
  • 2 is a literal value
  • = and the * are called operators

Expressions

let a = b * 2   // has 4 expressions
  • 2 is a literal value expression
  • b a variable expression
  • b*2 an arithmetic expression and also an expression statement
  • a = b*2 is an assignment expression

Operators

  • Assignment → = as in a = 2
  • Math → +, -, *, /
  • Compound Assignment → +=, -=, *=, /=
  • Increment/ Decrement → ++ or
  • Object Property Access → obj.a or person.age
  • Equality → ==, !=, ===, !==
  • Comparison → <, >, ≤, ≥
  • Logical → &&, ||

Values and Types

  • number
  • string → indicated by either “ “ or ‘ ‘
  • boolean (true or false)
  • arrays
  • objects
  • functions

Converting between Types — Coercion

  • Using a method like Number() or toString() is explicit coercion
  • If you compare values using the == operator, JavaScript will convert them in order to perform the operation, i.e. “99.99” == 99.99 — this is called implicit coercion

Variables

Blocks

Conditionals

  • If/Else statements → If clause need a condition that either returns true or false and will thus run a block of logic. The else clause will run if “if” is not true
if(age > 18) {console.log(“You old enough to drive”);} else {console.log(“You need to have a few more birthdays until you’re    old enough to drive”);}
  • Switch statements → can be used as a shorthand for a lot of if/else statements
  • Ternary Operator → (is this condition true) ? then do this : else do this instead

Loops

  • While loop → repeats a block of statements until a condition no longer holds true
while (age < 18) {console.log(“I am still not an adult”);}
  • Do … While loop → tests the conditional after the first iteration
  • For loop → Good if you only want to run the loop for a specific amount of time. Less prone to infinite loops.
for (let i = 0; i ≤ 9; i++) {console.log(i);}// will output 0 1 2 3 4 5 6 7 8 9

Functions

function sayName() {console.log(“My name is Sibylle”);}
function sayName(name) {console.log(“My name is ” + name);}

Scope

Photo by Priscilla Du Preez on Unsplash

Some closing remarks

  • Code is every bit as much, if not more, for the developer as for the compiler
  • The choices you make about how to write a program matter not only to you but to your other team members and even to your future self.

Resources

--

--

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
Sibylle Sehl

Software Engineer at ResearchGate // MSc Computer Science Grad - University of Edinburgh //@freeCodeCamp 2018 Top Contributor // Passionate Problem-Solver