Random Learning - an overlooked detail
I just learned that declaring a variable using 'const' doesn't mean it can't be altered, it just means that the variable can't be reassigned.
For example:
const arr = [];
arr.push(10) //Adds 10 to the arr without any problem, whereas
arr = [10] //Throws an error saying "TypeError: Assignment to constant variable."
Just learned it as I observed the array "header" towards the end of this video How to convert "camelCase" to "Camel Case"? - Javascript For Beginners II · Developer Pro
----------------------------------------------|||||||||||||||||||||||---------------------------------------------------
And one more thing..... to convert "camelCase" to "Camel Case",
"const newText = string.replace(/([A-Z]+)/g, ' $1')
.replace(/^./, str => str.toUpperCase() )"
can be used instead of
"const newText = string
.replace(/([a-z])([A-Z])/g, "$1 $2")
.replace(/([A-Z])([a-z])/g, " $1$2")
.replace(/\ +/g, " ");
const nextString = newText[0].toUpperCase() + newText.slice(1);" to do the exact same thing.
Works for any type of string and that "+" after "[A-Z]" makes all the difference.
6
4 comments
Prudhvi Raj Maddukuri
5
Random Learning - an overlooked detail
Developer Pro
skool.com/developerpro
Learn how to code. Make money. Have fun. Enjoy life.
Leaderboard (30-day)
Powered by