Mehrdad Mehrdad - 1 year ago 73
Javascript Question

Is es6 string template updated when variable inside it updates

Suppose I have a snippet as follows:

var temp='';
var template=`I am a ${temp}`;
var temp='developer';

So when I access template after second assignment of
what will be the result? Does es6 string template is a dynamic template or static as it is created?

Answer Source

It's static. You can think of it like a string.format from another language. In order for it to be dynamic it would need to be watching variables which would cost a great deal in terms of performance and flexibility.

If you're looking for string binding in HTML, look in to a framework like AngularJS or ReactJS or KnockoutJS or VueJS or RivetsJS or a dozen others.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download