JavaScript
In this article, we’ll learn the basics of JavaScript.
Let’s start.
JavaScript is a dynamic programming language that’s used for web development, It is used both on the client-side and server-side that allows you to make web pages interactive.
Initially, JavaScript’s name changed several times:
- Its code name was Mocha.
- In the Netscape Navigator 2.0 betas (September 1995), it was called LiveScript.
- In Netscape Navigator 2.0 beta 3 (December 1995), it got its final name, JavaScript.
Why JavaScript?
- All popular web browsers support JavaScript as they provide built-in execution environments.
- JavaScript is a weakly typed language, where certain types are implicitly cast (depending on the operation).
- JavaScript is an object-oriented programming language that uses prototypes rather than using classes for inheritance.
- It is a light-weighted and interpreted language.
How to write our 1st JS code?
Create a html file and between the <body>tag you need to open a <script> tag and type your java script code like mentioned below.
After you save it and open it from any browser, you will get a pop-up message.
var / let / const in JavaScript
var
Variable means anything that can vary. In JavaScript, a variable stores the data value that can be changed later on.
Use the reserved keyword var to declare a variable in JavaScript.
let
- let cannot be Re declared.
- let must be Declared before use.
- let have Block Scope.
const
- const cannot be Re declared.
- const cannot be Reassigned.
- const have Block Scope.
Data Types in JavaScript
Data types in JavaScript describe the different types or kinds of data that you will be working with and storing in variables. It’s important that you learn each of these data types because otherwise data can get stored in an improper format which will result in issues in your code later on.
Arithmetic Operation in JavaScript
Get Gowsigan Pushpanathan’s stories in your inbox
Join Medium for free to get updates from this writer.
Arithmetic operators perform arithmetic on numbers (literals or variables).
Let’s see some examples.
The output of the above code is below.
JavaScript Functions
A JavaScript function is a block of code designed to perform a particular task. It is defined with the function keyword, followed by a name, followed by parentheses ().
There are mainly two advantages of JavaScript functions.
- Code re-usability: We can call a function several times so it save coding.
- Less coding: It makes our program compact. We don’t need to write many lines of code each time to perform a common task.
There are 3 types of functions in JavaScript:
- Named function
- Anonymous function
- Arrow functions
Arrow functions make your code more readable and structured. Arrow functions are kind of a anonymous functions (the functions without a name and not bound with an identifier). They don’t return any value and can declare without the function keyword.
JavaScript Objects
A JavaScript object is an entity having state and behavior (properties and method). JavaScript is an object-based language. Everything is an object in JavaScript.
There are 3 ways to create objects.
- By object literal
As you can see, property and value is separated by : (colon).
2. By creating instance of Object directly (using new keyword)
Here, new keyword is used to create object.
3. By using an object constructor (using new keyword)
Here, you need to create function with arguments. Each argument value can be assigned in the current object by using this keyword. The this keyword refers to the current object.
JavaScript Classes
In JavaScript, classes are the special type of functions. We can define the class just like function declarations and function expressions.
The JavaScript class contains various class members within a body including methods or constructor. The class is executed in strict mode. So, the code containing the silent error or mistake throws an error.
Conclusion
So far, we’ve covered the fundamentals of JavaScript as well as their most common basics via code examples. In the future, this knowledge will be utilized to understand JavaScript frameworks.
Thank you so much for reading my article and I hope you have a better idea from this article.
If you have any questions or suggestions, please send me your comment.
Thank you.






