The ABCs of Javascript (Part 1)

Hy Hy! Welcome back to my blog😍. Have you read through my last blog post - The struggles of landing your first tech role? Trust me, it's a nice read!💚


Introduction to Javascript

Today, I'll be writing about the Almighty javascript😋 . Do you know that javascript presently stands as one of the most popular and commonly used programming languages in the world? Yeah, it's that cool... JavaScript was invented by Brendan Eich in 1995 and has since been a major game changer in the world of programming

While HTML is majorly used to structure the site, we use CSS to communicate style information for the design and layout of the web page. On the other hand, Javascript is a scripting language that permits you to implement complex features on web pages to make them interactive. Javascript is a language that has quite a wide range of scope but in this post, we'll be talking about its basics. It is very advisable to understand the basics of HTML and CSS before venturing into Javascript.

Let's get into it

Linking our Javascript with our HTML

Just like our CSS stylesheet is linked into our HTML file using the link tag, we also link our javascript file as well. Create a new text document called main.js in your scripts folder and link it to your index.js file like this.

<script src="scripts/main.js"></script>

Insert this line of code before the closing tag of your HTML body element and you're good to go.

Variables and Constants

Due to the reactivity property that is majorly used in javascript, there is a constant need to store data. In JavaScript, a variable or constant is used to store a data value. The major difference between a variable and a constant is that, unlike the variable whose value can be changed, the value of a constant cannot be changed. Variables and constants can contain strings, numbers, and even functions (we'll learn more about these soon) that can be later utilized in the webpage. We can declare our variables using let and var keywords and we can declare our constants using the const keyword. In the next subheading- Data Types, I'll be declaring the following variables using the let keyword:

  1. javascriptString
  2. javascriptNumber
  3. javascriptBoolean
  4. javascriptUndefined
  5. javascriptNull

Data Types

- String

A string is used to store textual data. It is enclosed by a single quote 'ABC', double quote "ABC" or a backtick `` (backticks are used to embed variables and expressions into a string)

let javascriptString = "ABC";

- Number

A number denotes numeric values i.e. integers and floating numbers (decimals and exponentials). Unlike strings, numbers don't require quotes around them.

let javascriptNumber = 67;

- Boolean

The boolean data type has just two values - True and False

let javascriptBoolean = true;

- Undefined

The Undefined data type represents an unassigned value. When a variable is declared, but not assigned, then its value is undefined

let javascriptUndefined;

- Null

The Null data type describes a value that represents nothing. Unlike Undefined, Null data type is known to be nothing or non-existent.

let javascriptNull = null;

Operators

We have quite a number of operators in javascript, however, for this blog, we'll only be reviewing a few of them. An operator in javascript performs some operation on data values and delivers a result.

+

This operator adds two numbers together or combines two strings.

6 + 9; //result 15
'Hello ' + 'world!'; //result Helloworld

- * /

These operators work the exact same way they work in basic maths. They subtract, multiply and divide numeric values

9 - 6; //result 3
9 * 6; //result 54

++ and --

The former results in an increment by 1 while the latter leads to a decrement by 1

6 ++; //result 7
9 --; //result 8

=

This operator is used to assign value to a variable or constant as we have seen in the Data Type section.

===

This operator returns true if both values are equal and are of the same type.

x === y //result false

Yes! We have come to the end of this blog post. I personally don't like extremely long articles😐 so I'm deciding to keep this as brief as it can be. Part 2 of ABCs of Javascript will be out on my blog next week. In that part, we'll be talking about Javascript functions, conditionals, and events. See you there💛.