Picture of use of functions in JavaScript

Returning Value of Functions in JavaScript | Use of JavaScript

Returning Value of Functions in JavaScript | Use of JavaScript

In this article, you will get information about Returning Value of Functions in JavaScript. If you want to learn about it then you must read the full article till the end. I hope you will like this article.

Picture of use of functions in JavaScript




What is returning value of functions?

How to use functions in JavaScript?

How to implement functions in JavaScript?

If these entire questions are related to your query then you are at right place. Here you will get the right information about this topic.

If you want to become a successful web designer or front end designer then you must have good knowledge of JavaScript. So you can learn JavaScript from here.

If you want to learn about functions then you should read the previous article. You can move to the previous article from below link.

Use of Functions in JavaScript




If you want to boost your JavaScript programming knowledge then you must read this book. It is really a wonderful weapon to learn JavaScript.

Returning Value of Functions

Here I am giving you some useful points about returning value of functions in JavaScript.

  • Functions may return a value using keyword “return”.
  • Functions can only return one value.
  • Once a function returns a value, control returns back to the caller.




Example:

<!DOCTYPE html>
<html>
<head>
	<title>Return Value of functions</title>
</head>
<script type="text/javascript">
	function sum(a,b){
		return(a+b);
	}
</script>
<body>
<h1>Welcome</h1>
<script type="text/javascript">
	var s=sum(3,8);
	document.write("sum of a and b :"+s);
</script>
</body>
</html>




Output:

Returning Value of Function in JavaScript

Conclusion

Finally, I hope you got information about Returning value of functions in JavaScript. I hope now you understand how to use functions with returning value.




If you have any questions regarding this article then you can ask me in the comment section below.

Thank you for reading this article till the end.

Picture of use of functions in JavaScript

Use of Functions in JavaScript | Use of JavaScript With HTML File

Use of Functions in JavaScript | Use of JavaScript With HTML File

 

In this article, you will learn about the use of functions in JavaScript. If you are also interested to learn about this topic then you should read this article till the end. Here I will explain you this topic with the help of an example.




Picture of use of functions in JavaScript

What is the function in JavaScript?

How to use functions in JavaScript?

How to write a code of functions in JavaScript?

If you have also these questions then you are at right place. Here you will get the right information regarding this topic. I hope you will love this article.

You should also read them:

Control Statements in JavaScript

Use of Switch Case in JavaScript




If you want to boost your JavaScript programming knowledge then you must read this book. It is really a wonderful weapon to learn JavaScript.

Functions in JavaScript

  • Functions are a block of code designed to perform a certain action.
    • function functionName(variableList){
      
      }
  • For Example, You want to add a separate functionality in your webpage. Like you want to convert Kg in gm. Then you will write some code of JavaScript in a separate block. Or you want to calculate the percentage of a product then you will write some code of JavaScript in a block. Thus you can write many types of code in different blocks.
  • It means you want to do many tasks in a single webpage then you will give a separate block for a separate task. These blocks are called a function. And you can use them at a different time in different places.
  • And we need to give a separate name for a single block of function.
  • Here you need to write a keyword “function”, before the name of the function. And you need to write it in small letters.

Function Execution

  • The function is executed when
    • The function is invoked from another JS function.
    • The function is attached to some event and event occurs.

Why Function

  • You can reuse code.
  • The script inside the function is not executed until the function is invoked.

Variables in Functions

  • Local Variable
  • Global Variable

Local Variable

When you will create a variable under a function then it called a local variable. The variable’s functionality will work on the body of that function. You can create a variable by write “var” keyword. You cannot use local variable out of that function’s body.




For Example:

<script>

Function hello(){

Var x;

}

</script>

Global Variable

If you want to create a global variable then you will not write a “var” keyword while declaring a variable. You can use a global variable in your whole webpage.

For Example:

<script>

Function hello(){

Y=2;

}

</script>

Example:

<!DOCTYPE html>

<html>

<head>

<title>Functions in JavaScript</title>

</head>

<body>

<script type="text/javascript">




function skillmaking()

{

document.write("Welcome in SKILL MAKING");

}

</script>

<h1>

Welcome

</h1>

<script type="text/javascript">

skillmaking();

</script>

</body>

</html>

The output of The use of Functions in JavaScript:

Picture of use of functions in JavaScript




Conclusion

Finally, you got information about the use of functions in JavaScript. I hope you got the information which you want. If you find this article useful then please share it with your friends. Thank you for reading this article till the end.

Picture of Use of Prompt Box in JavaScript

Use of Prompt Box in JavaScript | Use of JavaScript with HTML

Use of Prompt Box in JavaScript | Use of JavaScript with HTML

 

In this article, I will share some information about JavaScript. Here you will get information about Use of Prompt Box in JavaScript. If you want to learn the use of the prompt box then you should read this article till the end. I hope you will love it.

What is Prompt Box in JavaScript?

How to use a prompt box in JavaScript?

How to use JavaScript with HTML file?




If you also having these questions then you should read this article till the end. Here you will get information about the use of Prompt Box in JavaScript.

You should also Read these articles:

Use of Alert Box in JavaScript

Use of Confirm Box in JavaScript

If you want to boost your JavaScript Programming knowledge then you must read this book. It will be helpful to grow your knowledge of JavaScript.

Prompt Box in JavaScript

  • A prompt box in often used if you want the user to input a value before entering a page.
  • When a prompt box pops up, the user will have to click either “OK” or “Cancel” to proceed after entering an input value.
  • If the user clicks “OK” the box returns the input value. If the user clicks “Cancel” the box returns null.
  • prompt(“message”,”defaultValue”);
  • Here the second argument “defaultValue” is optional. You can skip this argument.

Example:

<!DOCTYPE html>

<html>

<head>

<title>Pop Up Boxes</title>
<script type="text/javascript">
 var x=prompt("Enter a value: ","3"); 
if(x!=null)
{
 for(i=1;i<=10;i++)
 document.write("<br/>"+x+"x "+i+"= "+x*i);
 }
 </script>

</head>

<body>






<h1>Welcome</h1>
</body>



</html>

The output of Prompt Box:

Picture of Prompt Box in JavaScriipt    Picture of Prompt Box in JavaScriipt




Conclusion

Finally, you got information about the use of the prompt box in JavaScript. I hope you got some useful article. If you find it helpful then please share it with your friends. Thank you for reading this article till the end.

Picture of Confirm Box in JavaScript

Use of Confirm Box in JavaScript| Use of JavaScript with HTML file

Use of Confirm Box in JavaScript| Use of JavaScript with HTML file

 

In this article, I will share some information about the use of confirm box in JavaScript. If you also want to know the use of confirm box then you must read this article till the end.

In the previous article, you learned about the Use of Alert Box in JavaScript.

What is Confirm Box in JavaScript?

How to use confirm box in JavaScript?

If you have both these questions then you should read this article till the end. Here I will explain to you about this topic with an example.




If you want to boost your JavaScript Knowledge then you should buy this book. I recommend it for every JavaScript learner. You must read this.

Confirm Box

  1. Confirm box has two buttons where first one is “OK” and second one is “cancel”.
  2. Here the browser needs some confirmation from the user.
  3. When a confirm box popup, the user will have to click either “OK” or “Cancel” to proceed.
  4. If the user clicks “OK”, the box returns true. If the user clicks “Cancel”, the box returns false.

Code:

confirm(“Some Message”);

Example:

<!DOCTYPE html>

<html>

<head>

	<title>Pop Up Boxes</title>

<script type="text/javascript">

	var x=confirm("This is confirm box");

	if(x){

		document.getElementsByTagName("body")[0].style.backgroundColor="blue";

	}

</script>
</head>
<body>
<h1>Welcome</h1>
</body>






</html>

The output of Use of Confirm Box in JavaScript

Picture of Confirm Box in JavaScript

Conclusion

Finally, you got information about the use of confirm box in JavaScript. I hope you got some informative article. If you like it as useful then please share it with your friends. Thank you for reading this article till the end.




You should also read these articles.

Alert Box in JavaScript

Control Statements in JavaScript

Use of popup boxes in javascript

Use of Pop Up Boxes in JavaScript | Use of Alert Box in JavaScript

Use of Pop Up Boxes in JavaScript | Use of Alert Box in JavaScript

 

In this article, I will share some information about JavaScript. Here I will share a very important topic of JavaScript “Use of Pop Up Boxes in JavaScript” and “Use of Alert Box in JavaScript”. If you also want to know about this topic then you must read this article till the end.

Do you want to become a successful Web Developer?

Do you want to learn about the use of pop up boxes in JavaScript?




If your answer for both of these questions then you are at right place. Here I will explain to you about use of pop up boxed in JavaScript. I hope you will read this article till the end.

If you want to boost your JavaScript Knowledge then you must read this book which is given below.


You should also read these articles.

Switch Case in JavaScript

Introduction of JavaScript

Use of Pop Up Boxes in JavaScript

JavaScript has three kinds of Pop up boxes. The list of pop up boxes is given below.

  • Alert Box
  • Confirm Box
  • Prompt Box

First of all, let’s talk about Alert Box

  1. Use of Alert Box in JavaScript

  • JavaScript has a function of the name alert(). Where we give a message who appeared in the alert box.
  • It has a single button “OK”.
  • If you will use this code then an alert box will arise at the starting of the webpage. And the webpage will not proceed till you press the “OK” button.

Example of Alert Box

<!DOCTYPE html>

<html>

<head>

	<title>Pop Up Boxes</title>

</head>

<body>




<script type="text/javascript">

	alert("This is alert box");

</script>

</body>

</html>

The output of Alert Box

Alert Box in JavaScript




Conclusion

Finally, you got the information about the Use of the alert box in JavaScript. I hope you got this article helpful for you. In the upcoming article, I will share about Confirm box and Prompt box. I hope you will read them. Thank you for reading this article till the end. If this article is helpful for you then please share it with your friends.

 

use of switch case in javascript

Use of Switch Case in JavaScript | Use of JavaScript in HTML file

Use of Switch Case in JavaScript | Use of JavaScript in HTML file

 

In this article, you will get information about the use of switch case in JavaScript. This is also a very important chapter of JavaScript. If you want to become a successful JavaScript programmer then you must know about this chapter.




How to use switch case in JavaScript?

Do you want to become a successful web designer?

If you have these questions then you should read this article till the end. In this article, you will find that how to use switch case in JavaScript with an example. I hope you will love this article.

If you want to boost your JavaScript programming language then you must read this book. The book is given below.





You must read these articles to improve your JavaScript skills.

Introduction of JavaScript

Control Statements of JavaScript

Now let’s talk about the use of switch case in JavaScript.

  • Here we use switch keyword.
  • Write an expression for the switch to case.
  • The expression compares with all cases and when the case matches then the code will execute.
  • After a case, we write break keyword.
  • At the end, we write a default case and write some code in default.




Switch(expression){

                Case n1:

                                //code here

                                Break;

                Case n2:

                                //code here

                                Break;

                Case n3:

                                //code here

                                Break;

                Default:

                                //code here

                }




Example:

<!DOCTYPE html>

<html>

<head>

	<title>Switch Case in JavaScript</title>

</head>

<body>

<script type="text/javascript">

	var x=1+1;

	switch(x){

		case 1:

		document.write(x+" is one");

		break;

		case 2:

		document.write(x+" is two");

		break;

		case 3:

		document.write(x+" is three");

		break;

		default:

		document.write(x+" is negative");

		break;

	}

</script>

</body>

</html>




The output of Switch case in JavaScript:

picture of switch case in javascript




Conclusion

In this article, you get information about how to use switch case in JavaScript. Here you got your answer with example and the output of the code. Thank you for reading this article till the end. If you have any questions regarding this article then you should write down it in the comment section below.

use of else if ladder in javascript

Use of Else if Ladder | Control Statements in JavaScript

Use of Else if Ladder | Control Statements in JavaScript

In this article, you will get one also an important chapter of JavaScript. Here I will explain you else if ladder. It is also a control statement of JavaScript.




Do you want to become a good programmer of JavaScript?

Do you want to get deep knowledge of JavaScript?

How can use else if ladder in JavaScript?

If you have all these questions then you are at right place. Here I will explain to you how to use else if ladder.

If you want to boost your knowledge of JavaScript then I suggest you a book. You must read this book for deep knowledge of JavaScript.






You should also visit previous chapters of JavaScript.

Basics of JavaScript

Best Way to write JavaScript code with the html file

Control Statements of JavaScript

Now let’s talk about Else if ladder. Here some key points of else if ladder is given below. You must read these key points.

  • Here you can use else if condition many times.
  • If first condition is true then the code of the first condition will execute.
  • Only one condition will execute at a time.




Example:

<!DOCTYPE html>

<html>

<head>

<title>Else If Ladder Statements</title>

</head>

<body>

<script type="text/javascript">

var y=-25;

if(y>0){

document.write(y+" is a positive number.");

}

else if(y==0){

document.write(y+" is zero.");

}

else{

document.write(y+" is negative.");

}

</script>




</body>

</html>




The output of Else If Ladder:

else if ladder statement in javascriipt

Conclusion

In this article, you got that how to use else if ladder in JavaScript. Thank you for reading this article till the end. If you have any question regarding this article then you should write down your question in the comment section below.



if and if else statements in javascript

Control Statements in JavaScript | Use of If Else in JavaScript

Control Statements in JavaScript | Use of If Else in JavaScript

Today in this article I will tell you a very useful topic of JavaScript. This is the initial starting of JavaScript which you must learn. Here you will get information about how to use control statements in JavaScript. Mostly here you will get that how you can use if else control statements in JavaScript.

Do you want to learn JavaScript?

Do you want to become a successful web developer?

How to use if else control statements in JavaScript?

If all these above questions having in your mind then you are at right place. Here you will get right information.

If you want to boost your JavaScript programming language than you should buy this book which is given below.

Control Statements in JavaScript

  • JavaScript offers almost the same control statements as we have in C language.
    • If, if else
    • Switch
    • While
    • Dowhile
    • For
    • For in

In this article you will learn if and if else statements. Here you will get that how to use if condition and how to use else condition?

Use of if and if else conditions in JavaScript

If(condition){

                                //code here

                                }

If(condition){

                                //code here

                                }

Else{

                //code here

                }

Example:

<!DOCTYPE html>

<html>

<head>

	<title>If Else Statements</title>

</head>

<body>

<script type="text/javascript">

	var x=7;

	if(x>0){

		document.write(x+" is a positive number.");

	}

	</script>

<br><br>

	<script type="text/javascript">
var y=-25;
	if(y>=0){

		document.write(y+" is a positive number.");

	}

	else{

		document.write(y+" is a negative number.");

	}

</script>




</body>

</html>

Output of if and if else control statements:

basics of javascript

Basics of JavaScript | Use of JavaScript with HTML File

Basics of JavaScript | Use of JavaScript with HTML File

 

 

Do you want to learn Java Script?

Do you want to start JavaScript from basics?

Do you want easy to learn JavaScript?

You can make easy to learn JavaScript by this book. I will recommend you to buy this book to learn JavaScript.

You should also check these articles to learn JavaScript which are given below.

Introduction of JavaScript

Best Way to write JavaScript Code for HTML file

basics of javascript

If you have these questions in your mind then you are in right place. Here I will share my own thought and knowledge of JavaScript. In this article, we will start with the basics of JavaScript. First of all, we should know that these key points about JavaScript.

  • JavaScript is a programming language while HTML and CSS are not programming languages. We declare that what should show on a webpage like image, heading, paragraph etc. But HTML cannot take decisions. Thus HTML is not a programming language. And CSS is used for only decorating like border, background color, text color, text style etc. While JavaScript is a programming language. It can take decisions.
  • The statements of JavaScript are separated by semicolons.
  • JavaScript statements are composed of: Values, Operators, Expression, Keywords and Comments.

What are the Literals in JavaScript?

Absolute constants are called  literals.

  • 32.1 (Number)
  • 35 (Number)
  • “Hello” (String)

Literals are different from variables. Here we talk about absolute constants.

JavaScript Variables

  • Variables are used to store data values.
  • The var keyword is used to declare variables.

Ex.: var x=5;

Note: Here is not any garbage collection

JavaScript Operators

Operators are used to manipulate data and give a data as result.

  • 20-5
  • 3*6
  • 54/2
  • a=2

JavaScript Expressions

An expression is a combination of values, variables, and operators, which computes to a value.

A=25+14*21

Keywords in JavaScript

  • JavaScript has many keywords. As you saw above that var is a keyword.
  • As of now there are 63 keywords in JS.

Comments in JavaScript

  • Code after double slashes // or between /* and */ is treated as a comment.
  • Comments are ignored, and will not be executed.

Identifier Naming Rules

  • In JavaScript the first character must be a letter, an underscore (_), or a dollar sign ($).
  • Subsequent characters may be letters, digits, underscores or dollar signs.

Conclusion

In this article you read about Basics of JavaScript. You read JavaScript Literals, JavaScript operators, JavaScript Expressions, JavaScript Keywords, JavaScript Comments and Identifier naming rules. Thank you for reading this article till the end. I hope you love this article. If you love this article then you should show your love in the comment section below. And if you have any questions in your mind then you should write it on the comment section below.

Boost your JavaScript skills by this book.

javascript skillmaking

Best Ways to write JavaScript Code for HTML file

Best Ways to write JavaScript Code for HTML file

You should also read these articles

Table Tag

Introduction of JavaScript

Today in this article I will tell you something about JavaScript basics. If you have any problem to write JavaScript code or if you are a beginner in JavaScript then you are at right place. Here you can get the right answer for your query. Here you can get the best ways to write JavaScript Code for HTML file. I hope you will get your answer. These are some points may help you to write JavaScript Code




  • You can write JavaScript code in the same HTML file.
  • You can write JavaScript code into the same HTML file like this:
<script type=”text/javascript”>
-------------------------
-------------------------
</script>
  • You can also write JavaScript code in a separate file, which can be embedded into your HTML file. You don’t need to write <script> tag in your separate file which has .js extension.
  • You can embed your external .js file with your HTML file by follow this:
<script type=”text/javascript” src=”externalfile.js”>
</script>

If you want to boost your JavaScript knowledge then you should buy this book. This is recommended by me.




Write JavaScript Code into HTML file

  • JavaScript code must be inserted between <script> and </script> tags.
  • You can place JavaScript code at anywhere in HTML document (body or head).
  • You should start your JavaScript code like this
<script type=”text/javascript”>
</script>
  • The type attribute is not always required. JavaScript is the default scripting language in HTML.

Best Ways to write JavaScript Code

  • You can write JavaScript code into <head> tag.
  • You can write JavaScript code into <body> tag.
  • You can write JavaScript code into an external file.




  1. Write JavaScript Code into the head tag

If you want to write JavaScript code into <head> tag then you should follow this type to write your JavaScript code.

<html>

<head>

<script type=”text/javascript”>

document.write(“welcome”);

</script>

<body>

<h1>Welcome SKILLMAKING </h1>

</body>

</html>

Output:

write javascript code

  1. Write JavaScript Code into body tag

If you want to write JavaScript code into <body> tag then you should read this code which is given below. Here you can take an idea to write JavaScript code into body tag.




<html>

<head>

<title>SKILLMAKING</title>

</head>

<body>

<h1>Welcome SKILLMAKING </h1>

<script type=”text/javascript>

document.write(“welcome”);

</script>

</body>

</html>

write javascript code

  1. Write JavaScript code into external file

If you want to write JavaScript code into an external file then you should read this code which is given below.

<html>

<head>

<title>SKILLMAKING</title>

<script type=”text/javascript” src=”file.js”>

</script>

</head>

<body>

<h1>WELCOME </h1>

</body>

</html>

File.js file

document.write(“hello JavaScript”);

Output

write javascript code




Conclusion

So here you get the best ways to write JavaScript code for your HTML file. I hope you will get the right answer for your query. Thank you for reading this article till the end. If you have any question regarding this article then you should write them into the comment section below. If you love this article then show your love into the comment section below.