In website development, fundamentals of JavaScript plays a vital role as it makes the websites interactive. With the knowledge of HTML, CSS, and PHP one can learn JavaScript easily as all the languages are interlinked somehow.
As JavaScript is quite important, we will first start with a little introduction and then we will discuss some fundamentals of JavaScript, in that way you don’t have to switch sites while learning about JavaScript.
Starting JavaScript
In this era, everything is so easily accessible and it makes learning easy.
If you have a gadget (mobile, laptop, or PC) and good internet then stop wasting your valuable time on anything that won’t return you a good reward.
So, learn JavaScript as this won’t get old with time but give you a good future if you master it.
There are thousands of articles and JavaScript tutorials, and you can hop on those but let me tell you how you can easily get the idea steps by step about this language till you go towards an advanced level.
I will recommend some websites and YouTube channels and post some links for your easiness.
So, don’t worry, and let’s get started!!
In this article, we will learn about the basic concepts of JavaScript. We will cover topics such as
- Variables
- Data types
- Operators
- Functions
By the end of this article, you will have a strong understanding of how to use JavaScript to write programs that can run in your web browser.
What is JavaScript
JavaScript is a programming language that is used to make web pages interactive. For example, you can use JavaScript to add features such as animations, forms, and videos to your web page.
JavaScript is a client-side scripting language, which means that the code is executed on the user’s computer. This is in contrast to other languages such as PHP and ASP, which are executed on the server.
JavaScript is easy to learn and use. However, it can be difficult to master. This article will give you a good foundation in the basics of JavaScript so that you can start writing your programs.
So, starting with its fundamentals
Variables
A variable is a place to store a value. In JavaScript, there are three different types of variables:
- Local variables
- Global variables
- Session Storage variables
Local variables
They are only accessible within the function in which they are defined.
Global variables
They are accessible from anywhere in your code.
Session Storage variables
They are only accessible within the same session (i.e., they are not persisted across page reloads).
To create a variable, you use the var keyword, followed by the name of the variable. For example:
var myName = “John”;
This creates a variable called myName and assigns it the value “John”.
You can access the value of a variable by using the variable name. For example, the following code would display the value of myName in an alert box:
alert(myName);
You can also change the value of a variable by reassigning it. For example, the following code would change the value of myName to “Jane”:
myName = “Jane”;
Data Types
In JavaScript, six data types can be assigned to variables:
- String
- Number
- Boolean
- Bull
- Undefined
- Object
String
A string is a sequence of characters. For example, the following code would create a string variable called myName and assign it the value “John”:
var myName = “John”;
Number
A number is a numeric value. For example, the following code would create a number variable called myAge and assign it the value 20:
var myAge = 20;
Boolean
A boolean is a true/false value. For example, the following code would create a boolean variable called isValid and assign it the value true:
var isValid = true;
Null
Null is a special value that represents an empty value. For example, the following code would create a variable called myName and assign it the value null:
var myName = null;
Undefined
Undefined is a special value that represents a value that has not been set. For example, the following code would create a variable called myName and assign it the value undefined:
var myName = undefined;
Object
An object is a collection of key/value pairs. Like this is an object variable called the person and assign it the values “John” and 20 for the keys “name” and “age”:
var person = {
name: “John”,
age: 20
};
Operators
In JavaScript, there are five different types of operators:
- Arithmetic Operators
- Assignment Operators
- Conditional Operators
- Comparison Operators
- Logical Operators
Arithmetic Operators
It is uses to perform mathematical operations
Like
var s = 20, t = 8, u=5;
u = s + t; //addition is done and it returns 28
s = t – u; //subtraction is done and returns 3
t = s * u; //multiplication is done and returns 100
t = s/u; //division is done and returns 4
u = s % 2; //returns division remainder 0.1
Assignment Operators
Assignment operators assign values to the variables.
Like
var s = 8 , t = 20, u = 35;
s = t; //s would be 20
t += 1; //s would be 21
u -= 1; //s would be 34
Conditional Operators
It assigns some value to a variable based on some condition i.e True or False.
( 😕 ) is uses to express it.
Syntax is
Condition ? value1 : value2;
Comparison Operators
Compare two operands and then tells either it is true or false.
Like
var x = 7, y = 12, z = “7”;
var u = x;
x == z; // returns true
x > z; // returns false
Logical Operators
It combines two or more conditions.
Like
var x = 3, y = 15;
(x != y) && (x < y); // returns true.
Functions
A block of code is specified to perform a certain function
You can define a function in JavaScript using the function keyword. For example, the following code defines a function named myFunction that takes two parameters and returns the sum of those parameters:
function myFunction(a, b) {
return a + b;
If you want to dive in brief details on the fundamentals there are some tutorials on W3Schools.
It’s the best source for online learning as it has editable tutorials.
Object Oriented JavaScript
In Object-oriented JavaScript, you build classes to structure different objects that encapsulate functionality and data. It is the best scripting language for websites. JavaScript is all amount objects, so to learn object-oriented programming first you need to have a good understanding of objects.
In object-oriented programming, everything revolves around objects. To create an object, we uses a constructor function.
Syntax:
var obj = new Object();
Here is the recommended video to learn about object oriented JavaScript
Conclusion
Hope I gave you all a little bit of overview of how to start and learned about some basic knowledge about JavaScript. You can also read about the best frameworks in the JavaScript.
Now start learning and keep practicing all the web languages to be a freelancer in web development in the coming months. Just be patient and try learning everything that comes your way.