Let's Talk about
Javascript
Johan Esteban Higuita
Software Developer at Talent.com
Bioengineer - Universidad de Antioquia
Session 1
Let's Talk about Javascript
Let's Talk about Javascript
HackerRank Survey
Let's Talk about Javascript
Stack Overflow Survey
Most popular technologies
Most used tecnology
Most loved web framework
Let's Talk about Javascript
Dynamic
Weakly Typed
Just-in-time compiled
Multiparadigm
High level
Single-threaded
Non-blocking
Asynchronous
Prototype-based
Cross-platform
Let's Talk about Javascript
You do not have to tell Javascript what type of variable you are going to store
const name = "Juan";
const age = 21;
const languages = ["Javascript", "Ruby", "C++"];
public static void main(String[] args) {
String name = "Juan";
int age = 21;
String[] languages = {"Javascript", "PHP", "C++"};
}
Weakly typed language:
Javascript
Strong typed language:
Java
Let's Talk about Javascript
You are allowed to dynamically switch the type of data
let name = "Juan";
console.log(name); //Juan
name = 10;
console.log(name); //10
public static void main(String[] args) {
String name = "Juan";
System.out.print(name); //Juan
name = 10;
//error: incompatible types: int cannot be converted to String
}
Dynamic Language:
Javascript
Works
Error
Static Language:
Java
Let's Talk about Javascript
Concurrency: Multiple tasks progress simultaneously.
Parallelism: Multiple tasks are executed at the same time.
Single Thread
Multiple Thread
concurrent
parallel
no concurrent
no parallel
concurrent
parallel
concurrent
no parallel
parallel
concurrent
concurrent
Let's Talk about Javascript
Synchronous and blocking
Synchronous and non-blocking
Asynchronous and non-blocking
How can JavaScript be asynchronous and single threaded at the same time?
Javascript Model
(Polling)
Let's Talk about Javascript
How it works?
1. Stops HTML parsing and rendering.
2. Load JS file
3. Execute JS file
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>App Title</title>
<link rel="stylesheet" href="style.css">
<script src="main.js"></script>
</head>
<body>
<header>
<h1>App Header</h1>
</header>
<main>
<h4>Lorem</h4>
<p>Lorem ipsum dolor sit, amet consectetur adipisicing elit.
Reprehenderit consequuntur et autem nam placeat impedit dicta.
</p>
</main>
<button id="btn">Click me!</button>
</body>
</html>
// Javascript
const btn = document.getElementById("btn");
btn.addEventListener("click", () => alert("You clicked on me"))
index.html
main.js
!
?
Let's Talk about Javascript
<html>
<head> ... </head>
<body>
...
<script src="script.js">
....
</body>
</html>
<script src="script.js" defer>
<script src="script.js" async>
normal execution
defer execution
async execution
Code Time!
Let's Talk about Javascript
A web worker is a JavaScript program running on a different thread, in parallel with main thread.
Let's Talk about Javascript
How it works?
// Create Worker
worker = new Worker("workerFile.js");
// Receive data from the worker
worker.onmessage = function (event) {
const incommingData = event.data;
//do Something...
}
worker.terminate(); // Kill the worker
Browser
//Send data to the browser
const dataToSend = "Testing Web Workers";
postMessage(dataToSend);
workerFile.js
Code Time!
Let's Talk about Javascript
Thank you!