30th May 2021, 4:21 AM
𝗣𝗮𝘄𝗮𝗻 𝗞𝘂𝗺𝗮𝗿 🅟︎🅚︎
𝗣𝗮𝘄𝗮𝗻 𝗞𝘂𝗺𝗮𝗿 🅟︎🅚︎ - avatar
4 odpowiedzi
+ 3
because you use global variables, and global variables are properties of 'window'... as 'window' object has a still a property named 'name', wich is used to hold a string, any value assigned to it would be casted to a string. String objects have a match method, while Number object doesn't have such method (regex are used only on String). that's the reason why storing a number to the variable 'name' (despite the 'var' declaration) cast it to a string, and allow to call 'match' method on it ;)
30th May 2021, 4:44 AM
visph
visph - avatar
0
It's mean name is a global variable and it has string property. Do you have another way to assign value in number variable.
30th May 2021, 8:20 AM
𝗣𝗮𝘄𝗮𝗻 𝗞𝘂𝗺𝗮𝗿 🅟︎🅚︎
𝗣𝗮𝘄𝗮𝗻 𝗞𝘂𝗺𝗮𝗿 🅟︎🅚︎ - avatar
0
Thanks buddy
30th May 2021, 8:20 AM
𝗣𝗮𝘄𝗮𝗻 𝗞𝘂𝗺𝗮𝗿 🅟︎🅚︎
𝗣𝗮𝘄𝗮𝗻 𝗞𝘂𝗺𝗮𝗿 🅟︎🅚︎ - avatar
0
'name' is a builtin property of 'window', so its scope is the global scope... you can access it either by 'name', 'window.name', or even 'window["name"]... it's a kind of getter/setter wich convert any thing assigned to it as string: https://developer.mozilla.org/en-US/docs/Web/API/Window/name if you declare a variable in a local scope, then 'name' will refer to your 'normal' variable (but you still can access the property of 'window' through dot/bracket notation ;) in js all variable are usually duck typing, do I don't understand what you mean by "another way to assign value in NUMBER variable"?
30th May 2021, 8:29 AM
visph
visph - avatar