Skip to content
This repository has been archived by the owner on Aug 28, 2023. It is now read-only.

Latest commit

 

History

History
267 lines (180 loc) · 7.19 KB

lesson01.md

File metadata and controls

267 lines (180 loc) · 7.19 KB

Basic Frontend - Spring 2023

Lesson 1, Tuesday, 2023-03-16


Lesson overview

  • Introduction to JavaScript

Welcome to JavaScript!


It does not matter what we cover, but what you discover

- Noam Chomsky Victor Weisskopf

(recently learned that the quote is by Victor Weisskopf, a famous physicist, but it's often attributed to Chomsky because he mentioned in some interviews. Still a good quote.)


Questions

  • don't be shy (or scared), ask questions!
    • as many as possible
  • interrupt us
  • there are no bad questions
  • ask us to repeat
  • if something is not clear to you, it's likely that it's not clear for others

Pillars of Web Development

HTML CSS JavaScript
HTML5 CSS3 JS
Content Presentation Dynamic Effects
Nouns Adjectives Verbs
<p>Hey</p>  <!-- HTML: Adds a paragraph -->
p { color: red; }  /* CSS: Makes the paragraph red */
p.remove(); // JavaScript: removes the paragraph

JavaScript (JS) - What is it?

  • JS is a programming language (scripting language)
  • JS allows you to implement dynamic content and effects

JavaScript - History

  • Invented by Brendan Eich in 1995 for the Netscape browser
  • 1997: Standardized by ECMA as ECMA-262
  • 1998: ES2 released
  • 1999: ES3 released
  • umm...
  • ZZzzzzz...
  • 2009: ES5 released
  • 2015: ES6 released

JavaScript is Everywhere


Tools

We'll be using these tools during our course:

Please install Visual Studio Code for the next lesson


Additional Material


Names of Special Characters

( Parentheses ) < Angle brackets >
{ Braces, or curly braces } & Ampersand &
[ Brackets, or square brackets ] | Vertical bar, or pipe |
; Semicolon ; : Colon :
' Single quote ' # Hash or number sign #
" Double quote " ` Back tick `
_ Underscore _ * Asterisk *
/ Slash, or Forward slash / ~ Tilde ~
\ Backslash \ ^ Caret or circumflex ^

Let's start with JavaScript!

  • Open Google Chrome
  • Hit F12 key
  • Click on Console
  • Try entering something

What did you try? What did you see?


Numerical Operators

Basic mathematical operators:

  • + addition
  • - subtraction
  • * multiplication
  • / division
  • ** exponentiation

Practice

Let's say we want to go to the cinema with some friends (choose any number).

How many people are going to the cinema in total? Enter it to JavaScript Console.

A ticket to watch the movie costs 8€, let JavaScript compute how much we have to pay in total.

Harald and Woytek volunteered to pay for the tickets. Use JavaScript to compute how much each has to pay.


Data Types

A data type is defined by two things:

  1. A set of values
  2. A set of operators

The operators are used on the values.

2 and 3 are example values for the Number data type. + is an operator that we can use to perform an addition on 2 and 3.

When we say "Number data type", we mean all the possible number values plus all the operations we can perform with those values.


Data Type: String

  • A String is a sequence of characters
  • It starts and ends with a " double quote
  • Or it starts and ends with a ' single quote
  • Examples: "Hello", 'Mellina'

Try it out

Open the console, and type in the following strings:

  • Your first name
  • Your favorite food
  • Name of your favorite book / tv series / anime

Strings and Quotes

Strings start and end with (') or ("). But what if we want to add a quote within our string?

"He said: "Hello""

We must escape the quote with a backslash (\).

A backslash in a string means that the character right after the backslash is special:

"He said: \"Hello\""

Special Characters

If you want a backslash in a string, you need to escape it: "\\"

There are some special characters in strings, for example:

  • "\n" - new line
  • "\t" - tab

Quiz: Which strings are correct?

"Hello"
'World'
"He said "hello" to me"
'Let's go!'
""
'This is a\nnew line'
'This is a backslash: \'

Solution

"Hello"                        // CORRECT
'World'                        // CORRECT
"He said "hello" to me"        // WRONG - unescaped quotes
'Let's go!'                    // WRONG - unescaped '
""                             // CORRECT
'This is a\nnew line'          // CORRECT
'This is a backslash: \'       // WRONG - escaped '