Posts

Building objects in JavaScript.

Image
 Math : Math function in JavaScript  from here you can take almost everything about math objects in JavaScript. Basically, Math objects have built-in properties and methods for dealing with mathematical calculations in javascript.  it also has many other built-in functions of javascript. for example, the random function returns some random numerical values. String: It looks like we have a bunch of methods and properties here but as we know string is primitive types. primitive types don't have methods and properties only objects do have the same, so why we have this?  this thing happens because in javascript we have two types of strings. 1) String primitives and 2) String Objects.  when we use. (DOT) with string primitives, JavaScript internally covers this with string objects. we can't see that but we can work with the same. to see string object in more detail  click me.  from here you can see all properties and methods of String Object. let's see some...

Note 6 : Functions

Image
It is a fundamental building block of JavaScript. it is basically a set of statements to perform some tasks and calculate the value. while declaring any function we don't need to add semicolumn at the end like we have declared any variables before. but the functions are more than rather only declaring and calling we can make this more interesting by passing arguments and call that function. Here one thing we have to notice that when we pass in anything in the function call is known as an argument. like here in the above example printMessage('This is the message') the sting here in 'This is the message' is an argument. and a message is written in the function printMessage(message) is a parameter here in printMessage function. the main fundamental things here to work like this is we can reuse the printMessage function. a function may have multiple parameters. the default value of the parameter is undefined. Types of function : or we can write this like this. the funct...

Note 5: Arrays.

Image
Sometimes we have to deal with a list of objects. for example a list of products in shopping carts or selected color from the list. In this kind of situation, we use arrays to store that list. so here is our array of 3 elements if we expend them we will also have an index of each element. and that index determines the position of that element. so, the index of the first element will be 0. next of that will be 1, and so on... and also if we want to access the element of the array we can use index. here in the example, we have selected the first index element which is "Red". As we know JavaScript is a dynamic language so if we change the value of the array the element with different dataType it will change accordingly. and the same rules also apply to the array. also, the objects in the array are dynamic. in other programming languages, we can store the element in the array of the same type but in JavaScript, we can store any type of object in the array. so now we have three st...