Tech Returners

JAVASCRIPT




The Story of Javascript

  • JavaScript is the programming language of HTML and the Web.
  • Back in the beginning of the the Web, when the first browsers were being created (Netscape vs Internet Explorer), Marc Andreessen (the co-creator of the Mosaic/Netscape Navigator browser, whose engine is now used to power Firefox) realised the Web needed to become more dynamic - It was all HTML and CSS at the time, and there was limited interaction.
  • So they experimented using different languages that had already existed to allow data to be dynamically manipulated through websites, and were not too happy with the results.
  • They recruited Brendan Eich to try embedding one of these languages, but in the end, he decided to create a language that would be prototype-based, and JavaScript was born.
Eich wrote JS in 10 days, in May 1995
Prototype object oriented programming uses generalized objects, which can then be cloned and extended. Using fruit as an example, a "fruit" object would represent the properties and functionality of fruit in general. A "banana" object would be cloned from the "fruit" object, and would also be extended to include general properties specific to bananas. Each individual "banana" object would be cloned from the generic "banana" object.

Prototype-based programming is a style of object-oriented programming in which behaviour reuse (known as inheritance ) is performed via a process of reusing existing objects via delegation that serve as prototypes.

But wait! What even is Programming?

  • Programming is the way humans tell computers to do logical things for them in a systematic fashion. It lets humans create ways for other people to interact using computers.
  • There are a wide variety of programming languages, BUT to decide which to use, we need to decide what we want to use it FOR, and then pick the language best suited for the use.
  • Programming languages are organised into paradigms , that is - ways of thinking and communicating with the computer.
Common programming paradigms include:

  • imperative which allows side effects,
  • functional which disallows side effects,
  • declarative which does not state the order in which operations execute,
  • object-oriented which groups code together with the state the code modifies,
  • procedural which groups code into functions,
  • logic which has a particular style of execution model coupled to a particular style of syntax and grammar, and
  • symbolic programming which has a particular style of syntax and grammar

An algorithm for making a cup of tea

  • Put the teabag in a cup.
  • Fill the kettle with water.
  • Boil the water in the kettle.
  • Pour some of the boiled water into the cup.
  • Add milk to the cup.
  • Add sugar to the cup.
  • Stir the tea.
  • Drink the tea.

Why Javascript?

  • Multi-paradigm (it can accommodate a range of thinking/programming styles)
  • Prototype-based (things that you have defined can be changed easily)
  • Designed to be used for the Web (whereas other languages have been designed for scientific computing, e.g. Python - although Python is a very flexible language too, or native application development, e.g. Swift / Objective C for iOS, and .NET for Windows)
  • Full-stack language (it can be used both on the client and server - other languages, such as Python or Ruby, are server-side languages)

So... how do I start using JavaScript?


Javascript picture

  • Because JavaScript is a standard Web technology, you can write it directly in your browser

Data Types

var example = 'hello';  // example is a String
var example = 20;       // example is a Number
var example = true;     // example is a Boolean
var example = false;    // example is still a Boolean

  • A variable is what JavaScript uses to store, organise and manage raw data which is being handled by functions & expressions. Variables are therefore manipulated by functions and expressions.
  • JavaScript uses semicolons, like CSS does, to decide when to stop executing a particular task.

Functions

function multiplyByTwo(num) {
   return num * 2;
}
  • A JavaScript function is a block of code designed to perform a particular task.
  • A function is executed when "something" invokes it (calls it).
  • You can use the same code many times with different arguments, to produce different results.
  • A JavaScript function is defined with the function keyword, followed by a name, followed by parentheses ().
  • The code to be executed, by the function, is placed inside curly brackets: {}

Tasks

  • Write a function that multiplies a number by 10
  • Write a function that divides a number by 2
  • Write a function that checks if the given number is greater than 20
  • Write a function that checks if the given argument is equal to 35
  • Write a function that takes 2 arguments and adds them together
  • Write a function that takes 2 arguments and divides the first argument by the second argument
  • Write a function that takes 1 argument, a name and returns a greeting and the name
https://jsbin.com/nutevuriqa/edit?js,console

Additional materials

and there's also a useful blog with advice on where to start
https://medium.freecodecamp.org/a-beginners-javascript-study-plan-27f1d698ea5e

How to Embed Images from Google Photos into your Website
https://www.labnol.org/internet/embed-google-photos-in-website/29194/

jQuery is next...
Click the link Below