Basics Of JavaScript

Basics Of JavaScript

WHAT IS JAVASCRIPT?

Javascript is a dynamic Programming Language that is used for web development, in web applications. it allows you to implement different features on web pages that can not be done with only HTML and CSS. This foundation will set you up for understanding the more complex concepts you’ll encounter later.

WHAT IS A CONSOLE?

The console is a panel that displays important messages, like errors, for developers. If you want to see things appear on your screen, you can print or login to your console directly.

In JavaScript, the console keyword refers to an object, a collection of data and actions that you can use in your code. Keywords are words that are built into the JavaScript language, so the computer recognizes them and treats them specially.

One method that is built into the console object is the .log() method. When we write console.log() what we put inside the parentheses will get printed, or logged on to the console.

Now let us look at this:

console.log (3);

In the example above, it logs 3 to the console while the semicolon indicates the end of a statement. Although in JavaScript your code will usually run as intended without a semicolon, but highly recommended, to learn the habit of ending each statement with a semicolon so you never leave one out in the instances where they are necessary.
It is useful for you to print your values to the console, so you can see the result of what you are doing.
having said all of this, Comment is quite important in Javascript too.

WHAT ARE THE COMMENTS?

Comments are used to explain your Javascript Code to make it more readable for other developers.
there are different types of comments:

  1. A single-line comment will comment out a single line and it is indicated with two forward slashes // coming after it.
 // Prints 3 to the console
 console.log(3);

Here, "// Prints 3 to the console" is a comment.

  1. A multi-line comment comments out multiple lines and it implies /* to begin the comment and */ to end the comment.
  /*
This is an example of the code I used in 
implementing my game website but I 
 don't want to disclose it yet.
 */

The comment above is a perfect example where you might use a multi-line comment. moving forward, I will be telling you what Data types do in Javascript.

WHAT ARE DATA TYPES?

Data Types are the classifications that specify which type of Value a variable has. In JavaScript, there are seven fundamental data types:

  • Numbers: Any number, including numbers with decimals: 6, 12, 1516, 23.14

  • String: Any grouping of characters on your keyboard (letters, numbers, spaces, symbols, etc.) surrounded by single quotes: '.......' or double quotes " ....." though single quotes most time is preferred.

  • Boolean: This data type only has two possible values— either True or False (without quotes). It’s helpful to think of booleans as on and off switches or as the answers to a “yes” or “no” question.

  • Null: This data type represents the intentional absence of a value and is represented by the keyword null (without quotes).

These types are considered primitive data types. They are the most basic data types in the language. Objects are more complex, and you’ll learn much more about them as you progress through JavaScript. At first, seven types may not seem like that many, but soon you’ll observe the world opens with possibilities once you start leveraging each one. As you learn more about objects, you’ll be able to create complex collections of data.

But before we do that, I will like you to get comfortable with strings and numbers.

 console.log('The Writer address: 
 4, Broadway Street, Lagos');
 console.log(10);

Above, a string was printed. The string isn’t just a single word, it includes both upper and lowercase, spaces, and punctuation. Next, we printed the number 10 where we did not make use of quotes (").

now, let us talk about arithmetic operators, this is a character that performs a task in your code. JavaScript has several built-in arithmetic operators, that allow us to perform mathematical calculations on numbers. Below are the operators and their corresponding symbols.

  1. Add: +

  2. Subtract: -

  3. Multiply: *

  4. Divide: /

  5. Remainder: %

console.log(4 + 4); // Prints 8
console.log(7 - 5); // Prints 2
console.log(4 * 1); // Print 4
console.log(10 / 2); // Prints 5

When we console.log() the computer will evaluate the expression inside the parentheses and print that result to the console. If we wanted to print the characters 3 + 4, we would wrap them in quotes and print them as a string.

Recall that when we console.log() the computer will evaluate the expression inside the parentheses and print that result to the console. If we wanted to print the characters 3 + 4, we would wrap them in quotes and print them as a string.

console.log(11 % 3); // Prints 2
console.log(12 % 3); // Prints 0

The remainder operator returns the number that remains after the right-hand number and divides it into the left-hand number as many times as it evenly can: 11 % 3 equals 2 because 3 fits into 11 three times, leaving 2 as the remainder.

Despite this, let us look at what Boolean is with an example below:

the data type below returns false when parsed as a value to Boolean method.

let print0 = Boolean('');
let print1 = Boolean(undefined);
let print2 = Boolean(null);
let print3 = Boolean(0);
let print4 = Boolean(NaN);

console.log(print0) //-> false
console.log(typeof print0) //-> boolean
//------------------------//
console.log(print1) //-> false
console.log(typeof print1) //-> boolean
//------------------------//
console.log(print2) //-> false
console.log(typeof print2) //-> boolean
//------------------------//
console.log(print3) //-> false
console.log(typeof print3) //-> boolean
//------------------------//
console.log(print4) //-> false
console.log(typeof print4) //-> boolean

Other values different from the above return false

let print0 = Boolean(' ');
let print1 = Boolean(1321);
let print2 = Boolean('Hello World');
let print3 = Boolean('true'); 
let print4 = Boolean(1);

console.log(print0) //-> true
console.log(typeof print0) //-> boolean
//------------------------//
console.log(print1) //-> true
console.log(typeof print1) //-> boolean
//------------------------//
console.log(print2) //-> true
console.log(typeof print2) //-> boolean
//------------------------//
console.log(print3) //-> true
console.log(typeof print3) //-> boolean
//------------------------//
console.log(print4) //-> true
console.log(typeof print4) //-> boolean

From the code example above, the boolean has the answers to “yes” or “no” and "true or false"questions. it, therefore, shows how the number () methods can be used to convert a string, boolean and null to numbers.

In conclusion,

you have learnt about Javascript basics, where we discussed the following:

  • console

  • Comments

  • Arithmetic Operators

  • Data types

we have come to the end of this tutorial, thank you for sparing time to read this article, feel free to ask questions. you van also reach me on twitter https://twitter.com/tech_Olaide or send me an email on

Thank You.