JavaScript - The Engine of the Web 🛩
August 10, 2022 ¿Ves algún error? Corregir artículo
In the world of web development, the most important language is undoubtedly JavaScript - a dynamically typed, interpreted language that in my personal opinion is very easy to learn.
Its main function is to execute code within the client (our browser), but in recent years multiple tools have been created that allow JavaScript to create code for mobile apps, desktop applications, microcontrollers, and even artificial intelligence.
It was created in 1995 by Brendan Eich and its file extension is "js".
Declaring Variables and Constants in JavaScript
Currently in JavaScript we use the reserved words let and const to create variables and constants respectively.
let aVariable = "I am a variable"
const aConstant = "I am a constant"
As you can see, no type annotations are made since JavaScript is dynamically typed, so we can change the variable's value regardless of type.
let aVariable = "I am a text"
aVariable = 45
Functions
Functions are blocks of code that allow us to execute a set of code lines when invoked. They were created to improve code structure and reuse code that we need to repeat.
function sayHiToUser(name){
console.log("Hi " + name)
}
sayHiToUser("Carlos")
sayHiToUser("Anastasia")
sayHiToUser("Mitya")
// > Hi Carlos
// > Hi Anastasia
// > Hi Mitya
With functions we can group different types of procedures like reducing a product's stock, changing a user's password, etc.
Conditional Structures
Within the language we can also check certain conditions and execute code depending on whether they're met or not.
if(age>18){
console.log("welcome to the party")
}else{
console.log("maybe the next year...")
}
There are others like else if or switch case, but for now and as a basic condition, the if control structure should suffice.
Loops
Loops are found in all programming languages and allow us to perform tasks repetitively until a certain condition is met.
const numberOfHi = 10
for (let i = 0; i < numberOfHi; i++) {
console.log("Hi "+ i)
}
There's also another type of loop where we can perform an action while a condition is not met, called a while loop.
This is Just the Beginning
As you can see, this is just the beginning of getting to know this programming language that is so in demand and with which many programmers work. If you're interested in having a private JavaScript class from scratch, contact me on my Instagram @carlos97cgr tell me why you want to learn JavaScript and let's have a free private session.