Building objects in JavaScript.
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 useful methods.
- in the above example message. replace function is returning new string it is not modifying the original one. as same we have message.toLowerCase and message.toUpperCase.
- one thing we have to see that here Escape notation is also very important.
- let' see this with example. if we write a single quote in the string it will not allow you directly but you can use this like the example below.
- also, the important method is string.split it will make an array of each element of a string.
- in the above, we see \' is used to add a single quote in our string also we can use \n for a new line in our string. but there is some limitation of this like they don't allow us to visualize the output.
- here is an example, in the above, we can see the output is different then the string we have written like... we write the line in a single line, and output is divided in two-line because we have use\n in our string. or we can do like this below...
- previously we have object literals, Boolean literals, string literals but with es-6 we have template literals.
- so what we have code in our file we have the same output in output screen.
- this is particular useful when we want to sent email from our application
Date Objects:
- For more details about JavaScript date objects click me.
- one thing is confusing about the date function is here month is 0 base which means 0 represents January and 11 represents December.
Comments
Post a Comment