Found 6710 Articles for Javascript

How to access 'this' keyword inside an arrow function in JavaScript?

vineeth.mariserla
Updated on 01-Aug-2019 14:12:25

569 Views

"this" keyword in an arrow functionThe JavaScript 'this' keyword refers to the object it belongs to. In an arrow function, 'this' belongs to a global object. Inside a simple function, there might be chances that 'this' keyword can result in undefined but in an arrow function it results in an exact value.ExampleLive Demo    function Student(fname, grade) {       this.fname = fname;       this.grade = grade;       this.details = function() {          return () => {             document.write(`Hi, I'm ${this.fname} from ${this.grade} grade`);          };       }    } let info = new Student('picaso', 'seventh'); let printInfo = info.details(); printInfo(); OutputHi, I'm picaso from seventh grade

How to convert JavaScript objects to primitive data types manually?

Lokesh Yadav
Updated on 09-Dec-2022 05:13:04

644 Views

In this article we are going to discuss how to convert JavaScript objects to primitive data types manually with suitables examples in JavaScript. Primitive data types are nothing but a string, number, boolean, etc. To convert objects to primitive data types, javascript has provided some methods such as toString(), toDateString(), valueOf(), etc. Using these methods javascript objects can be easily converted to primitive data types. Using the toString() method This method returns a string value representing the string format of the given object. The syntax to convert a javascript object into a primitive date type (string, in this example) is ... Read More

How to convert a JSON string into a JavaScript object?

Lokesh Yadav
Updated on 09-Dec-2022 05:11:36

3K+ Views

In this article we are going to discuss how to convert a JSON string into a JavaScript object with suitables examples in JavaScript. There are two possible ways to convert a JSON string into a Javascript object – eval() and parse(). The usage of eval() method is unsafe and not preferred. It is vulnerabable to hackers. The parse() method is preferred in general anytime. The typical application for JSON is Data transfer to and from a web server. The data that has been sent from a server is always a JSON string. Using JSON.parse(), we can convert the JSON string ... Read More

How to convert a value to a number in JavaScript?

Lokesh Yadav
Updated on 08-Dec-2022 08:18:08

4K+ Views

In this article we are going to discuss how to convert a value to a number in JavaScript. JavaScript has introduced Number(), parseInt(), parseFloat() methods to convert a value into a number and also we can achieve it by using (+) unary operator. These mentioned methods can convert number strings to numbers and Boolean values to 1's or 0's. Let’s us discuss these above mentioned methods briefly. We’ll discuss the 4 possible ways to convert a value to a number with an example each. Number() parseInt() parseFloat() Unary Opertaor(+) Example 1 The following is an example program to ... Read More

What is the use of Math.asinh() and Math.acosh() functions in javascript?

vineeth.mariserla
Updated on 31-Jul-2019 14:04:10

157 Views

Math.asinh() and Math.acosh() functions are used to find the hyperbolic arc-sine and hyperbolic arc-cosine of a number respectively. These functions are static methods of Math, therefore they are always used as Math.asinh() and Math.acosh(), rather than as methods of a math object created.Math.asinh()This method is used to find the hyperbolic arc-sine of a number. It takes a number as a parameter and returns hyperbolic sine value.ExampleLive Demo document.write(Math.asinh(2)); document.write(""); document.write(Math.asinh(7)); Output1.4436354751788103 2.644120761058629Math.acosh()This method is used to find the hyperbolic arc-cosine of a number. It takes a number ... Read More

What is the use of Math.imul( ) Function in JavaScript?

vineeth.mariserla
Updated on 31-Jul-2019 13:44:55

170 Views

Math.imul( )Unlike other multiplying functions, the Math.imul() function returns the result of the C-like 32-bit multiplication of the two parameters. Its application is very high in projects like Emscripten. syntaxvar product = Math.imul(a, b);This method takes two numbers and gives out their multiplication value.Example-1In the following example, two normal integers were given as parameters to the method Math.Imul() and the obtained result is displayed as shown in the output.Live Demo document.write(Math.imul(3, 4)); document.write(""); document.write(Math.imul(-3, 4)); Output12 -12Example-2In the following example, c-like 32-bit values were given as parameters to ... Read More

How to find the cube root of a number in JavaScript?

Lokesh Yadav
Updated on 08-Dec-2022 08:16:58

3K+ Views

In this article we are going to discuss how find the cube root of a number with the help of suitable examples in JavaScript. Using Math object in JavaScript any kind of operation can be done. Math.cbrt(), Math.pow() are the methods especially used to find the cube root of a number and also we can achieve it by using ** operator. It takes a number as a parameter and returns its cube root. To find the cube root of a number in JavaScript, there are three possible ways. The way to do it is by using cbrt() method, second way ... Read More

How to convert a date object's content into json in JavaScript?

Manisha Patil
Updated on 04-Aug-2022 10:21:22

1K+ Views

The contents of the specified date object are converted into a string using the date.toJSON() function. Applying date() constructor, the date object is generated. Dates describe a particular moment in time. The value of the Date object is described by a string that is returned by the toJSON() function (using toISOString()). In general, this function is programmed to automatically meaningfully serialise Date objects during JSON serialisation. The DateObj is a valid Date object produced by the Date() constructor function, and its data has been transformed into a string. Here are some additional codes for the procedure mentioned below in the ... Read More

What is the importance of Symbol.isConcatSpreadable in JavaScript?

vineeth.mariserla
Updated on 31-Jul-2019 09:21:18

212 Views

Symbol.isConcatSpreadableThis well-known symbol is used to configure if an object should be flattened to its array elements when using the Array.prototype.concat() method. If it is false then there is no flattening of the array takes place. By default, the Symbol.IsConcatSpreadable is true. Therefore until and unless it is not declared explicitly flattening of the array can't be avoided.Without SymbolExampleIn the following example, the symbol Symbol.IsConcatSpreadable was doesn't stated explicitly. So by default, the array was flattened as shown in the output. var arr1 = ['mango', 'apple', 'guava']; var arr2 = ['cashew', 'pista', 'bhadham']; ... Read More

What is the importance of ES6's template strings in JavaScript?

vineeth.mariserla
Updated on 30-Jul-2019 22:30:26

163 Views

ES6's template strings is a new way to combine strings. We already have methods such as join(), concat() etc to combine strings but the template strings method is the most sophisticated because it’s more readable, no backslash to escape quotes and no more messy plus operators.Using concat() and join()ExampleIn the following example join() and concat() methods are used to combine strings. If we observe carefully the code looks very messy.Live Demo const platform = 'Tutorix'; const joinMethod = ['The', 'best', 'e-learning', 'platform', 'is', platform].join(' '); document.write(joinMethod); ... Read More

Advertisements