Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is ${variable} in javascript [duplicate]

Tags:

javascript

I have seen the using of:

${startX} ${startY}

in javascript. That is totally new for me. I like the idea to use it, but don't know it is proove.

let cumulativePercent = 0;

function getCoordinatesForPercent(percent) {
  const x = Math.cos(2 * Math.PI * percent);
  const y = Math.sin(2 * Math.PI * percent);
  return [x, y];
}

const [startX, startY] = getCoordinatesForPercent(cumulativePercent);

const pathData = [
    `M ${startX} ${startY}`, // Move
    `A 1 1 0 ${largeArcFlag} 1 ${endX} ${endY}`, // Arc
    `L 0 0`, // Line
  ].join(' ');

I would write it like this:

  const pathData = [
    `M` + startX + ` ` + startY,
    ...

Does it works in jQuery also? Thx for any description-link in advance.

like image 655
hamburger Avatar asked Jan 24 '17 13:01

hamburger


People also ask

What is ${ variable in JavaScript?

A JavaScript variable is simply a name of storage location. There are two types of variables in JavaScript : local variable and global variable. There are some rules while declaring a JavaScript variable (also known as identifiers). Name must start with a letter (a to z or A to Z), underscore( _ ), or dollar( $ ) sign.

How do you duplicate variables?

Right-click the variable that you want to duplicate and select Copy.

What are the three types of variables in JavaScript?

In JavaScript, there are three different variable types: var , let , and const . Each of these variables have several rules around how they should be used, and have different characteristics. In this tutorial, we are going to explore the basics of variables in JavaScript.

What are the two types of variables in JavaScript?

JavaScript variables have only two scopes. Global Variables − A global variable has global scope which means it can be defined anywhere in your JavaScript code. Local Variables − A local variable will be visible only within a function where it is defined. Function parameters are always local to that function.

What is shallow copy and Deepcopy in JavaScript?

This is known as shallow copy. The newly created object has the same memory address as the old one. Hence, any change made to either of them changes the attributes for both. To overcome this problem, deep copy is used. If one of them is removed from memory, the other one ceases to exist.


1 Answers

Template literals is an ES6 capability -- https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Template_literals. It is independent of JQuery and other libraries. The way that you have it written should work.

like image 96
Max Sindwani Avatar answered Oct 15 '22 08:10

Max Sindwani