JavaScript doesn’t have typed parameters or variables. The function expects a string and does things in the function body which converts the object into a string. JS shares this behavior with all dynamically typed languages and it’s extremely useful in some contexts and extremely frustrating in others. It’s down to what it’s being used for. Dynamic languages make excellent scripting languages, see Python really just being a souped up shell lang
The function expects a string and does things in the function body which converts the object into a string.
… These are different words that describe exactly what I’m saying. I’m saying: in the place where there should be a string argument, because the function expects one, there is not a string argument, but a number argument. (Not an object like you keep saying.)
I know all that stuff about dynamically typed languages. I’m just saying that the function is being used incorrectly here.
You cannot have a string argument, arguments and variables in JS don’t have a type. All you have in JS is objects. Actual functions, like full on functionfoo(){}are still objects, like you can actually store data on the things.
I think you confuse argument with parameter. You cannot specify the type of the parameter, but any argument you supply to a function in JS has a type. Every value in JS has a type, arguments included.
If I go:
const n =0.0000005;
console.log(typeof n);
The code above will print “number”. And you cannot assign n.foo = "metadata"; to this value of a primitive type. Not everything is an object.
Either way, arguments have types, values have types. The arguments in this case were of type “number”, when they should have been “string”.
JavaScript doesn’t have typed parameters or variables. The function expects a string and does things in the function body which converts the object into a string. JS shares this behavior with all dynamically typed languages and it’s extremely useful in some contexts and extremely frustrating in others. It’s down to what it’s being used for. Dynamic languages make excellent scripting languages, see Python really just being a souped up shell lang
… These are different words that describe exactly what I’m saying. I’m saying: in the place where there should be a string argument, because the function expects one, there is not a string argument, but a number argument. (Not an object like you keep saying.)
I know all that stuff about dynamically typed languages. I’m just saying that the function is being used incorrectly here.
You cannot have a string argument, arguments and variables in JS don’t have a type. All you have in JS is objects. Actual functions, like full on
function foo(){}
are still objects, like you can actually store data on the things.I think you confuse argument with parameter. You cannot specify the type of the parameter, but any argument you supply to a function in JS has a type. Every value in JS has a type, arguments included.
If I go:
const n = 0.0000005; console.log(typeof n);
The code above will print “number”. And you cannot assign
n.foo = "metadata";
to this value of a primitive type. Not everything is an object.Either way, arguments have types, values have types. The arguments in this case were of type “number”, when they should have been “string”.