Day 8 : Learning JS
Tags: javascript, 100daysofcode, webdev, beginners
Published: 2021-08-21 07:00:27



### Important point about objects in js

![js objects](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xo4196ni1ofw07mc9l3f.png)


----

### 3 and 3.0 ??
![Numbers in js](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1knw0z8enhkd8bpubm1q.png)

* When you do `typeof(null)` you will get the answer as `object`. A bug maybe??  Arrays are also objects...(subtype of)


---


### Why no () after `.length` of an array in js ??

Read this [stack-overflow](https://stackoverflow.com/questions/9041723/why-no-after-length-in-javascript) post.

---

### `shift()` and `pop()`.
Both are used to take out elements from the array. shift() starts from the beginning while pop from the end.

![pic](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/l081fu98xg45r2567jgy.png)

---

### for each loop in js
![for each in js](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/7ynin62nx4yyv75u5djs.png)

See that we are using back-ticks within that `console.log()` , it enables us to write variables inside the string using `${}`.

### `includes()` function in js
checks for substring for a string, or array values in case of an array and so on..

![includes in js](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/0j5a2jub6j84lf4rvzw9.png)

# types in js
![A](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/uyy5uwdv3sfx4si5tbyt.png)

* In js, variables don't have types, values do. 
![type of values](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/a5g31hs2aepq42be3vqo.png)


* In JS, if a variable has never been declared, or not assigned a value, it considers both as an "undefined" state.
```
var v;
typeof(v);   //undefined
typeof(w);   //undefined

hello = function(){};
typeof(hello);      //"function"
```

----

### NaN
NaN is a special value that sort of indicates that we've had an invalid numberic operation of some sort.

![NaN](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/k9lgqd5km1im7pimoprj.png)



----

### `new` keyword in js

![pic of new objects](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/7jr2ukoi36z40t5hsxdx.png)

In the first example below, it is used to instantaite an object of date subtype, while in the second, we are doing type conversion into string

![String()](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ejk355istvyq5ugunhxb.png)

Hence we can convert to string by two methods, first using that `String(num_variable)` and second using `num_variable.toString()`.

----


### Conversion of string to int
follow this [link](https://stackoverflow.com/questions/1133770/how-to-convert-a-string-to-an-integer-in-javascript)

---


### Falsy and Truthy in js
Falsy implies the values, that will be considered as `false`, if we try to convert or use then as boolean (using inside if or while statements).

![falsy](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/7ppia3d6sf79lbwlej9t.png)

The first value in the table is am empty string.

All other remaining values are truthy.


### Double equals vs Triple Equals
Double equals considers coersion, while triple equal don't. So, if both of our variables has the same type, then we can use any of these. 

![null == undefined ](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/nuidhv50dltj9pb4htee.png)