The comment tag is use to insert comments in the source code. Comments are not display in the browsers. We can use comments to explain our code, which can help us when we edit the source code at a later date. This is especially useful if we have a lot of code.
Type of JavaScript Comments
There are two type of JS Comments
- Single line comments.
- Multiple line comments.
Single Line Comments
Single line comments is represent by double forward slashes (//) is knows as Single line comments. It is generally use single line comments.
For example
<html>
<body>
<script>
// single line comment
document.write("hello Student");
</script>
</body>
</html>
Output : hello Student
Multiple Line Comments.
Multiple Line Comments is represent by forward slash with asterisk /* then asterisk with forward slash */ is knows as Multiple Line Comments. It is often use for formal documentation.
Syntax
/* hello
student
how are you */
Example
<html>
<body>
<script>
/* Slower one wide of off, Thakur swings across the line and edges it behind! Brilliant catch from Latham as he leaps across to his right and goes with his left hand to get more vertical reach. And grabs it one-handed! */
document.write(" multiple line comment");
</script>
</body>
</html>
Output : multiple line comment
JavaScript variable
Variable is an identifier that refers to the data item stores at a particular memory location is knows as JavaScript Variable.
Some rules while declaring a JavaScript variable
- Name must be start (a to z or A to Z), underscore( _ ), or dollar( $ ).
- After first letter we can use digits (0 to 9).
- JavaScript variables are case sensitive.
There are two types of JavaScript Variable.
- Local Variable
- Global Variable
Local Variable
Local Variable define is a Inside the function.
Global Variable
Global variable define is a global scope. it means accessible from anywhere.
Example
<html>
<body>
<script>
var x = 40;
var y = 3.5;
var a=x-y;
document.write(a);
</script>
</body>
</html>
Output : 36.5
3 Ways to Declare a JavaScript Variable
- let
- var
- Const
Data types
It is determines the type and the operations that can be perform on the data.
Types of data types
There are two types of data types
- Primitive data type
- Non Primitive data type
Primitive data type
There are five type Primitive data type in JS.
- String
- It is a represents sequence of characters such as Sanu, Sudhanshu.
- Number
- It is a represents numeric values such as 1,25,248.
- Null
- It is a represents null.
- Boolean
- It is a represents Boolean value either false or true.
- Undefined
- It is a represents undefined value.
Non Primitive data type
There are main three Non primitive data types
- Object
- It is a real world entities.
- Array
- It is a represents group of similar values.
- RegExp
- It is a represents regular expression.
If you have any queries regarding this article or if I have missed something on this topic, please feel free to add in the comment down below for the audience. See you guys in another article
To know more about JS please check Wikipedia Click here
Stay Connected Stay Safe. Thank you.
0 Comments