An Interest In:
Web News this Week
- March 3, 2024
- March 2, 2024
- March 1, 2024
- February 29, 2024
- February 28, 2024
- February 27, 2024
- February 26, 2024
Day 8 : Learning JS
Important point about objects in js
3 and 3.0 ??
- When you do
typeof(null)
you will get the answer asobject
. 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.
for each loop 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..
types in js
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); //undefinedtypeof(w); //undefinedhello = 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.
new
keyword in js
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
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).
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.
Original Link: https://dev.to/gauravshekhawat/day-8-learning-js-500
Dev To
An online community for sharing and discovering great ideas, having debates, and making friendsMore About this Source Visit Dev To