Getting Started with JavaScript | Community Session | Jadujobs

Asad Faraz
6 min readMar 14, 2021

--

Jadu first batch has 2 black belts

Hey guys, Thanks for being here!!! Let’s talk about our journey of MERN-stack at jadu.

08/03/2021

First-class of the week and I am very excited to tell you that today we started learning JavaScript programming language. Till now we learned HTML that is a markup language and CSS that is a styling language but from now on we will work on the programming language “JavaScript”.

JavaScript is among the best languages. It is a very powerful language and the only language in which we can do front-end and back-end programming. This is a very efficient programming language as compare to other languages and also directly executes in browsers.

So in our First Lecture, we learned the following things in javascript:

  • Variables
  • Printing values to the console
  • Data Types of Variables
  • Prompt
  • Control Statements
  • Difference between var, let, and const

Variable

Variable is a location in memory where we can store our data and use it throughout our program. We can either declare a variable without giving it an initial value or we can give it a value during declaration. Here are both examples.

var number;

var number = 10;

Printing values to the console

We can print anything we want on the console using the console.log() statement. Here are some examples.

console.log(“I am String”);

console.log(“3.13”);

Data Types of Variables

We have the following data types of variables:

  • String
  • Number
  • Boolean
  • Null
  • Undefined

To know the data type of a variable we can write:

var pi = 3.14;

console.log(typeof pi);

it will print the data type of pi that is a number. You can see more details about this from here.

Prompt

Using prompt, we can take input from a user when needed instead of using form sometimes. We can use prompts like this.

var name =prompt(“Enter your Name”);

The above line will prompt a window asking for the name of a user in a browser and when a user inputs its name then the name will store in the “name” variable.

Control Statements

Using control statements, we can apply conditions in programs. For example, if we check either a value is greater than or equal to 90 then give a student an A+ grade and if a value is greater than 70 give a B grade else give c grade. For this scenario, the code will be as follow.

If (num >= 90) {

Console.log(“Grade = A+);

}

Else if (num > 70) {

Console.log(“Grade = B”);

}

Else{

Console.log(“Grade = C”);

}

Difference between var, let, and const

There are 3 different types of variables we can use according to our needs.

The var type of variable has a global scope and we can access it from anywhere in the program. To use this we can write: var room = 6;

The let type of variable has block scope. For example, if we declare a value inside a statement it will not be accessible from outside that if. You can see it practically below.

If(condition){

Let num = 20;

}

Console.log(let);

This will through an error because we can’t use num outside of the if block. Let type of variable can only be used in the same block.

Const type of variable is used when you have a constant value throughout a program and you don’t want to change that value. For example, we have the value of pi which is super constant to 3.14. so we will use const type to declare this.

Const pi = 3.14;

Now the value of the pi variable will not change. If we try to change it in another place of a program that will through an error.

So the first class about JavaScript ends here.

09/03/2021

Today we have an amazing community session where everyone shared some interesting information about themselves or anything they experienced in their life. This was really fun. I really enjoyed it and learned a lot. I learned some new concepts there as well. Everyone seems very happy to be a part of the jadu family.

I find out a book in today’s session which is called “The cultural code”. It is a very amazing book and has the secrets of highly successful groups. I also like reading books and I think I will start reading this book soon as possible. One amazing thing I came to know today is that 2 of our jadu fellows are blackbelt in martial arts. It was interesting and I am surprised that one of them is a girl so stay away from both of them if you don’t want a punch on your face😊.

12/03/2021

First of all, let me tell you a very fantastic trick of adjusting items centered both vertically and horizontally using CSS. I learned this trick and it is very beneficial if you want to center a div. It is only 2 lines of code. Here it is, so to center an item both vertically and horizontally you just write:

.container{

Display: grid;

Plate-items: center;

}

And here your div with a class container is centered. Isn’t this trick quite interesting?

Okay so now let’s discuss today’s class. So today we learned the following things in JavaScript.

  • Switch Statements
  • Loops
  • Arrays
  • Objects

Switch

A switch statement is used for very simple conditions and it also keeps the code clean and more readable. Know more about the switch here.

Loops

Loops are super helpful and handy when it comes to executing a statement more than once. For example, if we want to execute this statement console.log(“Anything”) 100 times then instead of writing this line of code 100 times we can simply wrap this in a loop, and with a few lines of code, we can print this statement 100 times.

We have 3 types of loops:

For Loop

The syntax of for loop is as below.

for (initialize variable; condition; increment/decrement (change))

{

//any code here

}

While Loop

The syntax of the while loop is as below.

while (condition)

{

//any code here

Change of variable

}

In a while loop, we initialize our variable outside the loop and change it inside the loop to avoid an infinite loop.

Do While Loop

The syntax of the do-while loop is as below.

Do {

//any code here

}

while (condition)

In the do-while loop first, the code will execute even if a condition is not true and then for the second time execution of code the condition will be checked.

Arrays

Arrays in javascript are used to make a list of data. For example, we have a list of items to buy from a market. We can simply store those values in an array. We can also mix the values and it doesn’t matter if we store strings and integers in one list, we can do that. The syntax of arrays is as below.

Var items = [“Apple”, “shoes”, 39, 1.42, “BMW”, true];

We can easily loop through arrays elements and access them. If we want to access the first element of an array we can do that like this: items[0]; Arrays indexes start from 0 so 0 will point to the first element of an array.

To find the length of an array we can use the length property of the array. E.g. items.length; This statement will return the length of the item array.

Objects

Objects are the type of variables that can hold many values in key-value pair format. Objects are very useful to organize data. For example, we can store a person’s details inside an object without duplicating values.

Var person = { name: “jon”, age: 40, gender: “male”};

Now we can access the keys and values of the person object.

This is it for today, I am learning much new and exciting stuff with a great community and fellows at jadujobs.

--

--