-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
467 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,267 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"attachments": {}, | ||
"cell_type": "markdown", | ||
"metadata": { | ||
"dotnet_interactive": { | ||
"language": "csharp" | ||
}, | ||
"polyglot_notebook": { | ||
"kernelName": "csharp" | ||
} | ||
}, | ||
"source": [ | ||
"# Delcared Types" | ||
] | ||
}, | ||
{ | ||
"attachments": {}, | ||
"cell_type": "markdown", | ||
"metadata": { | ||
"dotnet_interactive": { | ||
"language": "csharp" | ||
}, | ||
"polyglot_notebook": { | ||
"kernelName": "csharp" | ||
} | ||
}, | ||
"source": [ | ||
"### `var`, `let` and `const` difference in JavaScript \n", | ||
"\n", | ||
"Learn From `ChatGPT`\n", | ||
"\n", | ||
"In JavaScript, var, let, and const are all used to declare variables, but they have some differences in terms of their behavior and scope." | ||
] | ||
}, | ||
{ | ||
"attachments": {}, | ||
"cell_type": "markdown", | ||
"metadata": { | ||
"dotnet_interactive": { | ||
"language": "csharp" | ||
}, | ||
"polyglot_notebook": { | ||
"kernelName": "csharp" | ||
} | ||
}, | ||
"source": [ | ||
"`var`: In JavaScript, var was the original way to declare a variable. It is function-scoped, which means that a variable declared with var exists throughout the whole function in which it is defined, including any nested functions. If a variable is declared with var outside a function, it becomes a global variable and is available throughout the whole program. One important thing to note is that var allows for variable hoisting, which means that the variable can be accessed before it is declared.\n", | ||
"\n", | ||
"Example:" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": { | ||
"dotnet_interactive": { | ||
"language": "javascript" | ||
}, | ||
"polyglot_notebook": { | ||
"kernelName": "javascript" | ||
}, | ||
"vscode": { | ||
"languageId": "polyglot-notebook" | ||
} | ||
}, | ||
"outputs": [], | ||
"source": [ | ||
"function exampleFunction() {\n", | ||
" var x = 1;\n", | ||
" if (true) {\n", | ||
" var x = 2; // This is the same variable as above - not a new one\n", | ||
" console.log(x); // outputs 2\n", | ||
" }\n", | ||
" console.log(x); // outputs 2\n", | ||
"}" | ||
] | ||
}, | ||
{ | ||
"attachments": {}, | ||
"cell_type": "markdown", | ||
"metadata": { | ||
"dotnet_interactive": { | ||
"language": "javascript" | ||
}, | ||
"polyglot_notebook": { | ||
"kernelName": "javascript" | ||
} | ||
}, | ||
"source": [ | ||
"`let`: let was introduced in ECMAScript 6 (ES6) as a new way to declare a variable. It is block-scoped, which means that a variable declared with let only exists within the block in which it is defined. Blocks include functions, loops, and statements that are surrounded by curly braces. Variables declared with let can be updated, but not redeclared.\n", | ||
"\n", | ||
"Example:" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 1, | ||
"metadata": { | ||
"dotnet_interactive": { | ||
"language": "javascript" | ||
}, | ||
"polyglot_notebook": { | ||
"kernelName": "javascript" | ||
}, | ||
"vscode": { | ||
"languageId": "polyglot-notebook" | ||
} | ||
}, | ||
"outputs": [], | ||
"source": [ | ||
"function exampleFunction() {\n", | ||
" let x = 1;\n", | ||
" if (true) {\n", | ||
" let x = 2; // This is a new variable with the same name as above\n", | ||
" console.log(x); // outputs 2\n", | ||
" }\n", | ||
" console.log(x); // outputs 1\n", | ||
"}" | ||
] | ||
}, | ||
{ | ||
"attachments": {}, | ||
"cell_type": "markdown", | ||
"metadata": { | ||
"dotnet_interactive": { | ||
"language": "javascript" | ||
}, | ||
"polyglot_notebook": { | ||
"kernelName": "javascript" | ||
} | ||
}, | ||
"source": [ | ||
"`const`: const was also introduced in ES6 as a way to declare variables. It is also block-scoped and cannot be reassigned, but it does not mean that the value cannot be changed. If a variable is declared with const, it must be assigned a value at the time of declaration and cannot be reassigned later in the code.\n", | ||
"\n", | ||
"Example:" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": { | ||
"dotnet_interactive": { | ||
"language": "javascript" | ||
}, | ||
"polyglot_notebook": { | ||
"kernelName": "javascript" | ||
}, | ||
"vscode": { | ||
"languageId": "polyglot-notebook" | ||
} | ||
}, | ||
"outputs": [], | ||
"source": [ | ||
"function exampleFunction() {\n", | ||
" const x = 1;\n", | ||
" if (true) {\n", | ||
" const x = 2; // This is a new variable with the same name as above\n", | ||
" console.log(x); // outputs 2\n", | ||
" }\n", | ||
" console.log(x); // outputs 1\n", | ||
"}" | ||
] | ||
}, | ||
{ | ||
"attachments": {}, | ||
"cell_type": "markdown", | ||
"metadata": { | ||
"dotnet_interactive": { | ||
"language": "javascript" | ||
}, | ||
"polyglot_notebook": { | ||
"kernelName": "javascript" | ||
} | ||
}, | ||
"source": [ | ||
"In `summary`, var is function-scoped, can be hoisted, and can be updated and redeclared. let and const are block-scoped, cannot be hoisted, and let can be updated but not redeclared, while const cannot be reassigned." | ||
] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": ".NET (C#)", | ||
"language": "C#", | ||
"name": ".net-csharp" | ||
}, | ||
"polyglot_notebook": { | ||
"kernelInfo": { | ||
"defaultKernelName": "csharp", | ||
"items": [ | ||
{ | ||
"aliases": [ | ||
"c#", | ||
"C#" | ||
], | ||
"languageName": "C#", | ||
"name": "csharp" | ||
}, | ||
{ | ||
"aliases": [ | ||
"frontend" | ||
], | ||
"languageName": null, | ||
"name": "vscode" | ||
}, | ||
{ | ||
"aliases": [ | ||
"js" | ||
], | ||
"languageName": "JavaScript", | ||
"name": "javascript" | ||
}, | ||
{ | ||
"aliases": [], | ||
"languageName": "KQL", | ||
"name": "kql" | ||
}, | ||
{ | ||
"aliases": [], | ||
"name": ".NET" | ||
}, | ||
{ | ||
"aliases": [ | ||
"f#", | ||
"F#" | ||
], | ||
"languageName": "F#", | ||
"name": "fsharp" | ||
}, | ||
{ | ||
"aliases": [], | ||
"languageName": "HTML", | ||
"name": "html" | ||
}, | ||
{ | ||
"aliases": [], | ||
"languageName": "Mermaid", | ||
"name": "mermaid" | ||
}, | ||
{ | ||
"aliases": [ | ||
"powershell" | ||
], | ||
"languageName": "PowerShell", | ||
"name": "pwsh" | ||
}, | ||
{ | ||
"aliases": [], | ||
"languageName": "SQL", | ||
"name": "sql" | ||
}, | ||
{ | ||
"aliases": [], | ||
"name": "value" | ||
}, | ||
{ | ||
"aliases": [], | ||
"name": "webview" | ||
} | ||
] | ||
} | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 2 | ||
} |
File renamed without changes.
Oops, something went wrong.