#Why can I declare the string variable inside a class but I can't inside a function?
20 messages · Page 1 of 1 (latest)
You can do type a variable inside a function
that error show because you are not declare your variables
use let or const
class a {
private x: number;
test() {
let num: number = 1
}
}
okay, is let a requirement inside a function? because i can initialized it outside the function.
thanks
because outside the function is a class
you said you learn Java right?
it uses defaults?
class in typescript is more or less the same with java class
properties typing is more or less the same with java
in java you do type variableName, in typescript you do variableName: type
but inside a function, it is not a class anymore, but classic javascript
I see
you declare a variable with let or const
in java you dont use any keyword to declare a variable, so maybe that's why you are confused
inside a function, I need to add let even though i specified its type? is this correct?