Hello to JavaScript!

Rida Jamil
Nerd For Tech

--

Hello World

Since the last couple of weeks, I’ve started learning JavaScript. Running the first Hello World” and other few simple syntaxes in console successfully, made me think that it would be a simple language just like HTML. But guess what? JS made me realize that my life was quite easier before I started learning it. I’ve taken stress over irrelevant bugs of life. Bugs in life are much easier to handle than bugs in JavaScript.

What is JavaScript actually?

JavaScript is basically the functioning of your HTML and CSS. It’s the gateway that connects both front-end and back-end, thus serving on both sides. If you see more into it, then JS is basically the only programming language that can be used in the front-end.

How do we connect JS with HTML?

JS Connect

JS files need to be mentioned at the end of our body tag, i.e just before the closing body tag. But why didn’t we link it within the head tag just like the CSS file? That’s particularly because all the body tags should be active on the page before they start functioning. Thus, if we input the JS file at the top, the file would execute without having the content activated within it. This might cause an error in the functioning of tags. To stop giving chance to such little bugs, we must put our JS file link at the bottom of our body.

Avocados or Milk-Cartons? Conditions in JavaScript

Avocados or Milk-Cartons?

Some of you might already have seen this old joke. And most of you would probably say that the wife asked to get 6 avocados. But if you look into the words of wife, they’re actually ambiguous. Well, that’s how words of wives are normally for husbands, heh!. Let’s just execute this example understood by the husband, using javascript.

So the wife asked the husband to buy one milk carton, thus:

var milkCartons = 1;

Then she said, if they have avocados, buy six. But she didn’t indicate to buy either 6 avocados or 6 cartons. Husband understood the words as: “ if they have avocados then buy 6 Cartons of milk.”

In Javascript, it is known as a conditional statement and is indicated by if-else.

if (condition= true) {

console.log (“Move forward”);

}

else {

console.log(“Move Back”);

}

//Where console.log is a function in javascript, used to print variables.

The result we got was the same as what the husband bought. Taa Daa! We have 6 cartons of milk in JavaScript.

Conclusion:

Once you start understanding javascript, you can play with it a lot. But once it starts messing with you, it could make you pull your hair out. So make sure you understand and practice its basics and cores thoroughly.

--

--

Rida Jamil
Nerd For Tech

Rida Jamil is a Web developer and learning to become a Full Stack Developer. Tech-writing is one of the many skills that make her stand out from her colleagues!