Basics Of Javascript
Tags: javascript, beginners, webdev, tutorial
Published: 2023-03-23 20:13:29

## WHAT IS JAVASCRIPT

JavaScript is a dynamic Programming Language that is used for web development, in <u>web applications</u>. it allows you inplement 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 will  encounter later.

## WHAT IS 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 log 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, learning the habit of ending each statement with a semicolon to learn a 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.


2. 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.
So moving forward, I will be telling you what Data types do in Javascript.

## WHAT ARE DATA TYPES?

Data Types are the classifications that specifies which type of Value a variable has. In JavaScript, there are Seven fundamentals data types:

1.  ** Numbers**: Any number, including numbers with decimals: 6, 
     12, 1516, 23.14

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

3. **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.

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

5. **Undefined**: This data type is denoted by the keyword 
   undefined(without quotes). It also represents the absence of a 
   value though it has a different use than null. undefined means 
   that a given value does not exist.

These types are considered _primitive_ data types. They are the most basic data types in the language. Objects are more complex, and you will learn much more about them as you progress through JavaScript. At first, seven types may not seem like that many, but soon you will observe the world opens with possibilities once you start leveraging each one. As you learn more about objects, you will 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 symbol.

Add: +

Subtract: -

Multiply: *

Divide: /

Remainder: %

```
 console.log(4 + 4); // Prints 8
 console.log(5 - 7); // Prints 12
 console.log(4 * 1); // Prints 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 divides 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.

In spite of 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 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 returns 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 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 olaideoluwatobiloba1@gmail.com

Thank You.