What is the best practice to name this in javascript? [closed] - javascript

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 3 years ago.
Improve this question
In our small team (5 human) we have problem naming this.
Some of us writes _this,some _self,some self,some instance,some i (short for instance)
let _this = this
let _i = this
let _instance = this
let self = this

Related

How can i write this JavaScript ternary shorter? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 2 years ago.
Improve this question
Here my ternary :
mode === 'edition' ? (this.editionMode = true, this.creationMode = false) : (this.creationMode = true, this.editionMode = false)
I think it's redundant, can i write this ternary in a better way ? Thanks !
this.editionMode = mode === 'edition';
this.creationMode = !this.editionMode;

Is a created element, considered as a child? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
In javascript if you have this by example:
const a = document.createElement("img");
a.src = "test.png";
document.getElementById("parent").appendChild(a);
Will this give true? -> document.getElementById("parent").hasChildNodes();
const a = document.createElement("img");
a.src = "https://www.gravatar.com/avatar/b4185aac47f6262b40dc8f11535a32c0?s=48&d=identicon&r=PG";
document.getElementById("parent").appendChild(a);
console.log(document.getElementById("parent").hasChildNodes());
<div id="parent"></div>

Store user input in an array or object [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 2 years ago.
Improve this question
I would like to know whether it is easier to store all the data from a text input where the user has to enter their surname in an array or in an object. And how do I do so?.
Thanks in advance
You could do something like this:
var dataArray = [];
function storeData() {
var data = document.getElementById("yourInput").value;
dataArray.push(data);
}
This method uses arrays - personally I find them more easier to use than objects.

what is the best way to write this: [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 3 years ago.
Improve this question
let valor = value.replace("'","")
valor=valor.replace('"',"")
//or
name=value.replace("'","").replace('"',"")
A better option might be to use a single .replace instead, and use a regular expression to match either ' or ":
const valor = value.replace(/['"]/g, '');

regular expression in javascript checking for "asdasd<something>asdsada" [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
how would I check for string
<something> in var string = "some chars <something> somechars"
You can use String.match():
var res = string.match(/<something>/g); // ["<something>"]
If there is no match, the value of res will be null. See example on JSFiddle.

Categories