Introduction

Let's start by distinguishing between these three languages, how they look like, and what they do.

What are HTML, CSS, and JS?

What is HTML, CSS, and JS?

So in summary:

  • HTML gives structure to a website. (like what would be the order of an element)
  • CSS makes it pretty (like the color of my elements)
  • JS makes it interactive (what happens if I click a button)

Why Learn JavaScript?

Although this course is focused on web applications, many of the principles can be used for other platforms. JavaScript is a very powerful programming language that, with the right tools, could allow you to create mobile apps, desktop apps, program robots or create powerful back ends.

Not to mention it's one of the most demanded programming languages for professional job opportunities and it's easy-to-learn syntax, it was the obvious choice when choosing a programming language for writing web applications. Even with interesting alternatives like Dart or Web Assembly, JavaScript is still the number one choice for everything related to front end programming.

Can I Use My Python knowledge in JavaScript

Yes, in the next lessons, we will cover the basics of javascript, but keep the following page bookmarked, because many of the concepts we will see, probably you've already seen while learning Python.

1. Data Types (primitives)

Python ConceptPython ExampleJavaScript ConceptJavaScript Example
Integerx = 5Numberlet x = 5;
Floaty = 3.14Numberlet y = 3.14;
Strings = 'hello'Stringlet s = 'hello';
Booleanb = TrueBooleanlet b = true;

2. Data operations

Python ConceptPython ExampleJavaScript ConceptJavaScript Example
Additionresult = x + yAdditionlet result = x + y;
Subtractionresult = x - ySubtractionlet result = x - y;
Multiplicationresult = x * yMultiplicationlet result = x * y;
Divisionresult = x / yDivisionlet result = x / y;

3. Variables

Python ConceptPython ExampleJavaScript ConceptJavaScript Example
Variable assignmentx = 10Variable assignmentlet x = 10;
ConstantsX = 10Constantsconst X = 10;

4. Conditionals

Python ConceptPython ExampleJavaScript ConceptJavaScript Example
If-elseif x > 0: print("Positive")If-elseif (x > 0) { console.log("Positive"); }
else: print("Non-positive")else { console.log("Non-positive"); }

5. Loops

Python ConceptPython ExampleJavaScript ConceptJavaScript Example
For loopfor i in range(3): print(i)For loopfor (let i = 0; i < 3; i++) { console.log(i); }
While loopwhile x > 0: x -= 1While loopwhile (x > 0) { x--; }

6. Functions

Python ConceptPython ExampleJavaScript ConceptJavaScript Example
Function definitiondef func(): return "Hello"Function definitionfunction func() { return "Hello"; }

7. Data structures (Array, objects)

Python ConceptPython ExampleJavaScript ConceptJavaScript Example
List (Array)my_list = [1, 2, 3]Arraylet myArray = [1, 2, 3];
Dictionary (Object)my_dict = {"key": "value"}Objectlet myObject = {"key": "value"};
List of Dictionariesmy_list = [{"key1": "value1"}, {"key2": "value2"}]Array of Objectslet myArray = [{"key1": "value1"}, {"key2": "value2"}];

8. Built-in methods for strings

Python ConceptPython ExampleJavaScript ConceptJavaScript Example
String lengthlength = len(s)String lengthlet length = s.length;
String concatenationcombined = s1 + s2String concatenationlet combined = s1 + s2;
String findindex = s.find('llo')String indexOflet index = s.indexOf('llo');

9. Built-in methods for arrays

Python ConceptPython ExampleJavaScript ConceptJavaScript Example
Append to arraymy_list.append(4)Push to arraymyArray.push(4);
Remove from arraymy_list.remove(2)Splice from arraymyArray.splice(myArray.indexOf(2), 1);
Array lengthlength = len(my_list)Array lengthlet length = myArray.length;
Access array elementelement = my_list[0]Access array elementlet element = myArray[0];
Sort arraymy_list.sort()Sort arraymyArray.sort();
Reverse arraymy_list.reverse()Reverse arraymyArray.reverse();

Topics to Review