what is JavaScript Array ?

Hello friends, in today’s post, we are starting you about HTML(what is JavaScript Array), what happens. How does the key work, so today you should tell about HTML.

JavaScript Arrays

JavaScript arrays are written with square brackets

array items can be separated with commas.

Now let us understand better with an example

Example

<script>
var name = ["x" , "y" , "c"];
</script>

In the above example, we have created an array named name, which contains three names.

array index starts from 0, which means first name will be [0] , second [1] , third [2]

JavaScript Objects

Just as [] is used to store an array, similarly {} is used to store an object.

But object properties are written with name:value, different properties can be separated with commas.

Example

<script>
var students = [1001:"x" , 1002:"y" , 1002:"c"];
</script>

In the above example the object students has 3 properties :1001 , 1002, 1003

typeof operator

You can use the typeof operator of JavaScript to check the type of a javascript variable.

Using the typeof operator, the type of a variable or an expression can be obtained.

Example

<script>
typeof ""; //string return करेंगा
typeof "html";//string return करेंगा
typeof "html in hindi";//string return करेंगा
</script>

उदाहरण

<script>
typeof 0 //number return करेगा
typeof 1 //number return करेगा
typeof 1.2 //number return करेगा
typeof (1) //number return करेगा
typeof (2-1) //number return करेगा
</script>

undefined

If we do not give any value to any variable, then we get type of undefined, as well as its value is also undefined.

Example

<script>
var name ; // value और type दोनों undefined होंगे </script>
Compare the above example with the example of string
So please read the whole lesson carefully, otherwise incomplete knowledge can be dangerous.
Now let's see how you can use undefined yourself.
Example
<script>

var name = undefined;// value और type दोनों undefined होंगे </script>

You must have seen the example of dynamic variable above, by this (by setting undefined) you can empty any variable.

Empty Values

Like we said to compare something above, if you have not noticed, let us tell you that empty value has nothing to do with undefined.

If you have read carefully, it must have confused you for sure.

Empty string has both value and type, so always keep in mind the difference between value and empty string without variable.

Example

<script>
var name = ""; // value will be empty "" (nothing will be displayed) and type will be string 
</script>

Null

There is nothing null in javacript, you can consider it as something that does not exist.

But unfortunately, null is the typeof object in JavaScript.

You can make an object empty by setting its value null in this way:

Example

<script>
var students = [1001:"x" , 1002:"y" , 1002:"c"];
students = null; // now value is null, but type is still object
</script>

You can also do this by setting undefined .

Example

<script>
var students = [1001:"x" , 1002:"y" , 1002:"c"];
students = undefined; //अब value undefined हो चुकी है , और type भी undefined |
</script>

Till now you must have got a lot of confusion between null and undefined, so let’s see

difference between undefined and null

undefined and null are same in value but different in type:

Example

<script>
will be typeof null // object
typeof undefined // will be undefined
undefined==null // true because value is the same
undefined===null //false because type is not same while returns true if both are present
</script>

More Topics-

Primitive Data

Primitive Data value is a simple data value, it does not contain any additional properties or methods.

If the typeof of the same value or variable is as follows then it can be primitive types

number

string

boolean

undefined

Let us understand better through an example:

उदाहरण

<script>
typeof "html" // string होगा
typeof 1.2 // number होगा
typeof true // boolean होगा
typeof false // boolean होगा
typeof x // will be undefined if x does not contain any value
</script>

Complex Data

By typeof operator you can get one of the two complex types.

functions

objects

The typeof operator will return an object of type objects , arrays , and null

But note that typeof operator does not return type object for functions.

Let us better understand the following typeof with the help of an example:

Example

<script>
typeof {1001:"x" , 1002:"y"}// object होगा
typeof [10,20,30,40] // object होगा
typeof null // object होगा
typeof function x(){} // function होगा
</script>

You must have noticed that in JavaScript array also has data type object.

reference – https://www.w3schools.com/js/js_arrays.asp

Request – If you found this post useful for you(what is JavaScript Array), then do not limit it to yourself(what is JavaScript Array), do share it

Leave a Comment