We need to write a function to remove duplicates from an array.
function(arr){
let unique=[];
for(let i=0;i<arr.length;i++){
if(unique.indexOf(arr[i])== -1)
{
unique.push(arr[i]);
}
}
}
return unique;
}
I am writing my experiences and learning to help others
We need to write a function to remove duplicates from an array.
function(arr){
let unique=[];
for(let i=0;i<arr.length;i++){
if(unique.indexOf(arr[i])== -1)
{
unique.push(arr[i]);
}
}
}
return unique;
}
lightweight: it takes very less system memory
cross platform: can be run on multiple platforms and systems
object oriented : js is a language based on object
JavaScript is one of the three core technologies(HTML & CSS)
JavaScript is most commonly used as a part of webpages. It can be used in different places.
A JavaScript object literal is like a comma separated name value pairs .
Ex: var myObject={name:”narendra”,height:180};
We can access the properties as myObject.name which gives “narendra”
Truthy Values:
“0”
“false”
empty functions
empty arrays
empty objects
typeof(null)
these above listed items are considered true in javascript
Falsy values:
false
0
“”
null
undefined
NaN(Not a number)
These are considered false.
When dealing with these truthy and falsy values we should be careful and always try to use “===” or “!==” when we need to compare .
“==” will not check for type but when we use “===” it will check for type also and returns true when type of variables on both sides is same.
Example:
if(3==”3″) will return true;
if(3 ===”3″) will return false;
p5.js is a JavaScript library which can be used by artists,designers,educators and beginners who want to code. Using p5.js we have a full set of drawing functionality and this is not limited to canvas alone, we can make use of addon libraries from p5.js and easily interact with other html objects like text, input, video, webcam and sound.
In JavaScript a number with leading zeros is considered to be in Octal system and it is read as octal value.
Ex:”0025″ is read as “21”.
In order to have its value preserved we should pass it as string.
Ex: myfunction(x){
alert(x);
}
we should call function as myfunction(“0026”)