Category: JavaScript

9 articles found.

Mathematical Operators In JavaScript

Mathematical Operators In JavaScript, arithmetic operators example, javascript quotient, javascript assignment operators, comparison operators in javascript, what does modulus do in javascript,

Hello everyone, I hope you are fine. In today's tutorial, we are gonna take a look at “ Mathematical operators in JavaScript” in detail. Performing math operator in different programing language is very common. JavaScript also allows several operators to help us in numbers. The mathematical operator in JavaScript is used for performing certain different tasks such as the final price of a financial transaction, browser windows size and calculating the range between the element in a website document. There are two types of operator that I am going to discuss in this tutorial. To perform an action between two variable or values we use mathematical operators. In the equation 3+2 = 5 ( + is a syntax). Java script has many different operators some are basic math operator and others are additionals operators particular to programming. A table of JavaScript Operators Let me explain to you all of these operators in detail. Addition and subtractions are the operators from basic maths. They are used to find the sum and difference of two numerical values. JavsScript has its own built-in calculator. All these mathematical operators can be directly performed in the console. As you have seen a simple example of addition and now I am going to explain it with detail. Now I will assign numerical values to a and b and place the sum in c. Output In a similar way, subtraction(-) also work with the same formula but will subtract the number. Output We can also do add and subtraction by the float ...

While Loop In JavaScript

While Loop In JavaScript, javascript while loop break, do while loop, while loop example, while loop countdown javascript, while loop example in javascript

Hello friends, I hope you all are feeling great today. In today’s tutorial, we will have a look at a detailed “ While Loop In JavaScript ” topic. It’s our 8th tutorial in JavaScript Series. Loops are used in programming and they offer the easiest and quickest way to do a repetitive task. In this article, we will learn about While and do..while statements as they are the most basic type of Loops. For example, if we want to display the same line “I am learning JavsScript” 10 times. Then this can be done with the help of loops easily rather than typing long code. It will save your time and energy. In JavaScript, while loops loop through a block of code until the specified condition is true. The condition is evaluated before executing the statement. The syntax of the while loop is very similar to i f statement. Syntax while (condition) { // execute this code as long as the condition is true } In the following example, we have to take a variable i = 1, and the while condition is that when it executes it should be less than 5. For each iteration of the loop, we will add one number. Output When we will run the above example, we will receive the following result. You might have already the idea what Infinite loop is because of its name. An infinite loop is a loop that will keep running forever. If you make an infinite loop by accident it can crash your browser. So it is really important the awareness of infinite loop otherwise can crash your computer or browser. Look at the example ...

For Loop In JavaScript

for loops in javascript for loop example javascript while loop for...in loop javascript for of loop javascript

Hello folks, I hope you are doing great in your life. In today’s tutorial, I am going to talk about “ For Loop In JavaScript”. This is our 7th tutorial of the JavaScript series. Loops are designed in JavaScript to automate the repetition task. You may have encountered a lot of time in programming that you have to repeat an action again and again. To help you in reducing the number of lines code and time, loops were created. There are five types of loops JavaScript have: For Loop will run the same code of block again and again repeatedly, for a specific number of time or as long as a certain condition is met. The For loop of JavaScript is similar to C language and Java for Loop. Syntax for (initialization; condition; final expression) { // code to be executed } The for loop is the most concise part of looping. There is three expression use in for Loop initialization, condition, and final expression. Let me show you a simple example of for loop. As you can see in the image that firstly, we initialize the for loop with let i = 0;. Its means that the loop begins with 0. Afterwards, we declared the condition to be i < 4; means that the loop will continue to run as long as i is less than 3. Our last expression is i++, it will increase by 1 each time the loops runs. Output All of these three expressions in for loop are optional. we can write the for statements without initializations. Look at the demonstration for more clarity. // declare variables outside the loop var i = 5; for (; ...

Switch Statement in JavaScript

Switch Statment in JavaScript javascript switch multiple case javascript switch case range javascript switch multiple case javascript switch return javascript switch case multiple expressions switch vs if else performance

Hello friends, I hope you all are doing great. In today’s tutorial, we will have a look at the detailed “ Switch Statement in JavaScript ”. It’s our 6th tutorial in JavaScript Series. As we have learned about the conditional statement and its types (if, if..else, If...else if) in the last article, a conditional statement is the most useful and common feature in the programming language. Switch is also a type of conditional statement and it will evaluate an expression against multiple possible cases and run one or more blocks of codes base on matching cases. The switched statement work almost as if...else if statement containing many blocks, and it does work so more efficiently than repeated if...else if statements. The switch statement is used to perform different action based on multiple cases. How does switch statement work? Syntax switch (expression) { case x: // case x code block (statement x) break; case y: // case y code block (statement y) break; default: // execute default code block (statement default) } As the name says break, When JavaScript reaches the break keyword, it breaks out of the switch block. It will only stop the execution of inside the block. It will continue until reaching the last break case. Eventually, reach the last case and the break keyword will end the switch block. If there is no case match then the default code block will run. There could be only one default keyword in the switch statement. The default keyword is optional, but it is ...

If Else Statement in JavaScript

If else Statement in JavaScript, If else condition in JavaScript,javascript conditional operator, javascript if else shorthand, different conditional statements, javascript if statement multiple conditions, javascript complex if statement, how to add multiple conditions in if statement javascript

Hello everyone, I hope you are having a fine day. In today’s tutorial, I am going to discuss the if-else statement in JavaScript and what are conditional statements in detail. In programming, while writing a program there may be an occasion where you need to adopt one out of a given set of paths. In such a case, you need to use conditional statements that allow your program to make the correct decision. Conditional statements are used to run a specific action based on the result of the different conditions (true or false). If the condition would be true one action would be performed and if the condition is false then another action would be performed. A few examples of JavaScript conditional statements: We have the following conditions in JavaScripts. If statement plays a very important role in JavaScript to make decisions. It will decide whether the statement is true or false and only run if the statement is true. Otherwise, the code block will be ignored if the statement is false. Syntax if (condition) { // block of code that will excute if the condition is true } Note: if is a lowercase letter and If or IF will cause a JavaScript error. A simple example to see how if statement work in javascript. Let’s suppose you are going to pay your electricity bill through an app where you have a certain amount of money already in your account. Your account money is 5000 and you have to pay the electricity bill of 700. Using the <= help you in finding that whether you have less than or ...

Variables In JavaScripts

variable in javascript, javascript variable scope, javascript variable types, use javascript variable in html, examples of variables in javascript

Hello everyone, I hope you are having a good day. In today's tutorial, I am going to tell you about "Variables in JavaScript". The topic, I am going to highlight today, is how to declare variables in JavaScript and types of Variable? JavaScript has variables too as many other programming languages, so let's get started with it: Variable means anything that can vary(change). In JavaScript, Variable holds the data value, in simple words, JavaScript variables are containers and can store the data value. Variable in JavaScript are declared with var (reserved keyword). Syntax var (Variable-Name) = value; In this example, we have declared two variables using var: number, string. we have assigned each variable a different value. The data value of the number is '5' and string data value is 'Hello". Let's have a look at few other examples: In this picture, you can see that int X = 5; String str = "Learning" But in JavaScript, Variable will be automatically detected and you don't have to define their data type that if they are integer or string etc. var myVarname = 10; alert(myVarname); myVarname = "This is a string value"; alert(myVarname) Look in this above example, in the beginning, myVarname variable is treated as int numeric type and with alert. Following that, we have worked on myVarname again as a string and showed it. May you have noticed that we have not defined their data types. Storing the value of a variable is called variable initialization. You can store the value of the ...

Basic Syntax And Rules In JavaScript

Fundamental Syntax And Rules In JavaScript, javascript syntax function, what is javascript, what is javascript coding, javascript coding examples, javascript syntax error

Welcome back, guys! I hope you are well and having a great day. In today's tutorial, I will discuss the new topic " Basic Syntax and Rules in JavaScript". Learning grammar for a spoken language is necessary before you start writing it. There are rules and regulations you have to follow to write. Similarly, all programming languages have their grammar/syntax and rules which you have to follow in order to execute. Let me show you an example. Alert(“I am learning JavaScript”); This code sample has uppercase "A" and instead of printing the expected "I am learning JavaScript". The error will appear (alert is not defined) and code would not run. So it is important to be careful with syntax. Here are some rules you should keep in mind. alert(“I am learning JavaScript on https://www.theengineeringprojects.com/”); The syntax of comment is similar to CSS. JavaScripts c omments are used to explain or understand the code, and to make it more readable. Suggestions or warnings can help the end-user too. With the help of comment, you can stop code from execution while running or testing alternative code. There are two types of comment in JavaScript. Single line comment represents double slash forward (//). You can use it before and after the code. When you add these two forward slashes (//), all of the code/text to right of them will be ignored. Y ou can see an example in the below picture. The multi-line comment is more convenient than single-line comment, you can use it as a single line ...

How to Include Javascript Code in HTML Page

Where To Add Your JavaScript File, how to include external javascript in html, how to create external javascript file, how to link javascript to html and css, javascript include external js

Hello, I hope you all are doing well. In the previous tutorial, I shared a detailed introduction to JavaScript, where we discussed the basics. Today, I am going to tell you in detail How to Include Javascript Code in HTML Page and many more things that can help you understand JavaScript easily. All right guys let's revise what we have learned in the past article, you saw me adding script & /script code at the bottom of the tags. Today, I will show you in detail what was the reason for adding the tags at the bottom and how can you add an external JS file. If you want to be an expert programmer, you should have a look at this Oracle Java Certification, it will surely excel your programming skills. We have two methods to include the JS code in the HTML file. script type="text/javascript" alert("I am learning JavaScript"); script type="text/javascript" src="Test.js" /script So, short scripts like this can be added at the bottom of the body content in HTML pages. In case, your JS content is large, has more than 10 lines of code and is full of links here and there. It's time to show you how to do this. Create a new file by pressing Ctrl + N and add your script alert("I am learning JavaScript"); content in this file. Save it with the name "Test.Js". All JavaScript files have a JS ending. Now go back to the "index.html" file and add the code as you see down. When you refresh the web browser then it will automatically reload and JS file through the source code. Look down the image. ...

Introduction to JavaScript

Introduction to JavaScript with complete Guide, what is javascript, javascript tutorial with examples, javascript tutorial for programmers, learn javascript step by step, complete javascript tutorial with examples

Hello folks, I hope you are having a great day. Today, I am going to start this new tutorial series on JavaScript and here's our 1st tutorial titled Introduction to JavaScript. This is a beginner level tutorial series, where we will start from very basics & will slowly move towards complex concepts. If you're not a beginner or looking for secure development training or advanced tutorials, stay tuned, more training is coming. We can use any development Editor for running JavaScript and for this tutorial series, I will use Microsoft Visual Studio Code, which is free to use & you can download it from official site. You don't need to be an expert programmer, in order to learn JavaScript, but you must have some basic knowledge of HTML & CSS. So, let's get started with today's lecture: So, now let's have a look at few uses / advantages of Javascript: <script> alert(“I am learning JavaScript”); </script> Steps to Follow: What Is The Best Way To Include JavaScript File in Html I am sure you all already know HTML and CSS but you have attempted to learn JavaScript many times but failed for some reason and you drop it. But I am sure now you are going to stick with me since I am going to describe you step by step each code. From the next lesson onward, I am going to tell you more in detail what is the Syntax of JavaScript and where to place JavaScript file. I hope you guys understand this lesson and I will see you in my next tutorial. Till then take care of yourself. If YOU have any ...