Use of # in JavaScript (outside of jQuery and CSS)? -


i know of use of # in jquery , css, in vanilla javascript environment has no jquery or css intervention, # have use?

yes, in javascript can use character # inside strings.

for example, # begins id selector in css, can use in js:

document.queryselector('#someid'); 

and in urls, # begins hash. in javascript can hash of object implements urlutils functionality using hash property:

location.hash; // '#somehash' location.hash = '#anotherhash'; 

you can use delimiter strings:

var arr = ['ab', 'c', 'de', 'fg', 'h', 'ij']; // longer var arr = 'ab#c#de#fg#h#ij'.split('#');       // shorter 

and of course may want string contain # character. in case, use #:

var str = 'this string has number sign @ end: #'; 

apart strings, can use # in regular expressions:

var rg = /#/; // matches character `#` literally 

Comments

Popular posts from this blog

java - UnknownEntityTypeException: Unable to locate persister (Hibernate 5.0) -

python - ValueError: empty vocabulary; perhaps the documents only contain stop words -

ubuntu - collect2: fatal error: ld terminated with signal 9 [Killed] -