Typescript variables: Difference between revisions

From wikinotes
(Created page with "= Assignment = <blockquote> <syntaxhighlight lang="typesript"> let name: string = "alex"; </syntaxhighlight> </blockquote><!-- Assignment --> = Scope = <blockquote> </blockquote><!-- Scope -->")
 
No edit summary
 
(3 intermediate revisions by the same user not shown)
Line 1: Line 1:
{{ NOTE |
see also [[javascript variables]] }}
= Assignment =
= Assignment =
<blockquote>
<blockquote>
<syntaxhighlight lang="typesript">
<syntaxhighlight lang="typescript">
let name: string = "alex";
let name: string = "alex";   // type annotation
let name = "alex";          // inferred type 'string'
let foo = bar.baz() as User; // type assertion (I know this is a user, but compiler won't)
</syntaxhighlight>
</syntaxhighlight>
</blockquote><!-- Assignment -->
</blockquote><!-- Assignment -->
= Scope =
<blockquote>
</blockquote><!-- Scope -->

Latest revision as of 00:41, 17 December 2022

NOTE:

see also javascript variables

Assignment

let name: string = "alex";   // type annotation
let name = "alex";           // inferred type 'string'
let foo = bar.baz() as User; // type assertion (I know this is a user, but compiler won't)