Javascript For Completely Beginners

Part 1 | Introduction To Terminologies

5 Min. Read
Nov 1, 2020

 javascript es6 ecmascript beginner tutorial

What is Programming?

Photo 1595644101020 4d83b3d355f7?ixid=mxwxmja3fdb8mhxwag90by1wywdlfhx8fgvufdb8fhw%3d&ixlib=rb 1.2

Programming is a process of writing instructions in a sequence so that the computer can fetch and execute them. We use programming languages to design and build software. In a web-application, designing and building webpages can be done with a combination of different languages like CSS, Javascript, and HTML. In this blog, I will specifically talk about Javascript.

In the context of a webpage, HTML represents the skeleton whereas CSS represents Skin/Muscles and Javascript puts life in it.

What is JavaScript?

JavaScript is a programming language that gives a soul to a webpage which makes our webpages alive. for eg:-A dead the body is a webpage when we add JS in it a dead body will be alive & starts walking and talking.

What is JavaScript Engine & how it works?

1*wfueusabqchwjhoikyrmyg

A JavaScript engine is a program that runs JS code. The engine reads the script then converts the script to the machine language because the computer only understands machine code. The V8 engine is supported in Chrome and Opera likewise, SpiderMonkey for Firefox whereas, SquirrelFish for Safari, etc.

What is a Code Editor and which one is the best to use?

In my opinion, a code editor is a supporting tool for every programming languages where we can write our codes for building software. There are different code editors but we(programmers) use them as per our taste. I mean to say that someone finds ‘Sublime Text’ so easy to use whereas some say ‘Visual Studio Code’ is the best though the purpose of using text editor is the same. If we are beginners, I suggest Visual Studio Code because I find some extra features than other editors but it depends upon your preference.

What does Developer Tool mean?

Chrome tools wordpress hero The developer tool is a set of tools that is available in a browser where we can test our codes, see errors, and also examine variables. We can inspect and debug the pages HTML, CSS, and JavaScript of any website that is currently open.
The example of a developer tool is Console. If you are learning JavaScript means you must be familiar with Console.

Javascript Basic Structure

1
2
3
4
5
6
7
8
9
10
11
<!DOCTYPE HTML>
<html>
  <body>
    <p>Before the script...</p>
    // We can use a <script> tag to add JavaScript code to a page.
    <script>
      alert( 'Hello, world!' );
    </script
    <p>...After the script.</p
  </body>
</html>

How to attach files, external files, inside <script> tag?

Script files are attached to HTML with the src attribute:

1
<script src="file.js"></script>

External Script files are attached to HTML with the src attribute:

1
<script src="/path/to/script.js"></script>

We can give a full URL as well. For instance:

1
<script src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js"></script>

A single <script> tag can’t have both the src attribute and code inside.

1
2
3
<script src="file.js">
  alert(1); // the content is ignored, because src is set
</script>

How to put comments in Java Script?

Comments are ignored by the engine. If we want to make clear about our codes to users we do comments. We can comment in two ways. If we have to comment in one line we give two forward slashes i.e // whereas If we have to give comments in multiline we start with a forward slash and an asterisk /* and end with an asterisk and a forward slash */.

For example,

1
2
3
4
5
//This is single line comment.//
/*
  This is multiline comment.
  This is second line.
  */

How to write code?

Codes are written in many statements separating with semicolons.

For example,

1
2
3
4
5
/* Two alerts Hello and world. Firstly,
computer will alert Hello and then will alert world.*/

alert('Hello'); alert('World');

Usually, statements are written on separate lines to make the code more readable:

1
2
3
4
5
// In Js semicolon can be omitted but I want always to insert semicolon at line breaks.

alert('Hello');
alert('World');

Is “use strict” that important you should care about?

"use strict" is the modern way of using JavaScript code and it is placed at the top of a script file. Modern js supports advanced language Structure, that enables use strict automatically.

What is a Variable?

Variable Variable is a pointer where we store data and assign value to it. We declare Variable to store data by using the var, let, or const keywords. Always declare a let for a variable declaration to run your codes at the local scope. let is a modern way of declaring variables whereas var is an old way. Variable name must contain only numbers, only letters, or the symbols $ and _. Variable naming must be meaningful. In the above diagram, the variable is pointing to data 1 and data2.

Simple Example:

1
2
3
4
5
6
7
let message;  //declaring a variable with the name "message"

message = 'Hello'; // store the

alert(message); // shows the variable content

We can also declare multiple variables in one line as in the example below:

1
2
3
let user = 'John', age = 25, message = 'Hello';

What is a Constant?

Constant

Constant is also like a variable but the difference is, constant cannot be assigned with another value once defined. This is why the same constant name cannot point to Data 2 once it’s pointed to Data 1. Some constants are named using capital letters and underscore to make a difference.

For instance:

To declare a constant (unchanging) variable, use const instead of let:

1
2
3
4
5
6
7
8
9
10
const myBirthday = '19.03.1980'; //declaring constant variable

myBirthday = '01.02.2000'; // error, can't reassign the constant value!

const COLOR_RED = "#F00"; //uppercase constant

let color = COLOR_RED;
alert(color); //#F00 will be the output

What are Data-Types?

Js type of datatype 13jan17 1418

In simple concept, Data types are Number, String, Boolean, Null, Undefined, BigInt.

For example:

  • Numbers means 123 or 14.34; Eg: let n = 123;
  • String means quotes: double quotes, single quotes, backticks; let name = "John";
  • Boolean means two values: true and false; let isGreater = 3 > 1; result comes true
  • Null represents “empty” or “unknown value” let age = null; means age is unknown.
  • Undefined is alike null but its not mean empty. It means variable if declared but not assigned, then its value is undefined. let age; shows undefined on alert.
  • Bigint means big integer value. Example 10n. The “n” at the end means it’s a BigInt. const bigInt = 1234567892345567788n;

What do alert and confirm mean?

Alert

Alert shows a message. Confirm shows a message and waits for the user to press “OK” or “Cancel”. It returns true for OK and false for Cancel.


Conclusion

In my experience its not that hard to understand the basic terminologies in Javascript. See you in the next chapter.

You might also like

JavaScript is a programming language that gives a soul to a webpage which makes our webpages alive. for eg: A dead the body is a webpage when we add JS in it a dead body will be alive & starts walking and talking.
Read More..


Write To Me

Hire me shiva bhusal
We'll never share your email with anyone else.
I'll never share your email with anyone else.