Here you can find my private notes about programming that I wanted to share with you. Feel free to filter based on the topic you want or search for something specific.
Strings in JavaScript are immutable which means that once a string is defined, it cannot be changed anymore. Trying to change a string with a standard String-function will only create a new string and not affect the original string. Consider the following example, where the value in string1 is not changed:
Inspired from an exercise in Hackerrank.com, I found the opportunity to present you the data types that JavaScript defines, which are the following six:
undefined
null
number
string
boolean
object
Arrays and functions are plain objects in JavaScript and they both belong to the object data type.
Using a variable as a regular expression to find all matches inside a string
Often I have to use a value from a variable and not a fixed string inside a regular expression. For example if I wanted to iterate over the english alphabet and find the number of occurrences of each letter inside a string, I had to do something like the following:
1
2
3
vartestString="Lorem ipsum dolor sit amet, consetetur sadipscing elitr.";varmatches=testString.match(/a/g).length;// do this for all the remaining letters
the previous example would work and would find all occurrences of “a”.