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
Post a Comment