DEV Community

Cover image for Day 8 : Learning JS
Gaurav-Shekhawat
Gaurav-Shekhawat

Posted on

Day 8 : Learning JS

Important point about objects in js

js objects


3 and 3.0 ??

Numbers in js

  • 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 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


for each loop in js

for each in js

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

types in js

A

  • In js, variables don't have types, values do.
    type of values

  • 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"
Enter fullscreen mode Exit fullscreen mode

NaN

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

NaN


new keyword in js

pic of new objects

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()

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


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

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

Top comments (2)

Collapse
 
gauravshekhawat profile image
Gaurav-Shekhawat

dev-to-uploads.s3.amazonaws.com/up...

This is am important image, go through it

Collapse
 
gauravshekhawat profile image
Gaurav-Shekhawat

The summary being that if your key value is stored in another variable , then you cannot use the dot syntax to access the property, and you have to use the [ box ] syntax