Javascript
cotrTypesBoolFalse
JavaScript Boolean False
false;
cotrFuncSyntax
JavaScript Function Syntax
// JavaScript Function Syntax// Basic function: function functionName(parameters) { ... }// Function with arguments: function functionName(arg1, arg2, ...) { ... }// Function with named arguments (using object destructuring): function functionName({arg1, arg2, ...}) { ... }
cotrTryCatch
JavaScript Try Catch
try { ${1:// Your code here}} catch (${2:exception}) { ${3:// Your code here}}
cotrInfo
JavaScript Info
Typing: Dynamically typedParadigm: Multi-paradigm: event-driven, functional, imperative, prototype-basedCompilation: Interpreted or just-in-time compiledConcurrency: Event loop model with support for asynchronous programming using callbacks, promises, and async/await
cotrEntry
JavaScript Entry Point
// JavaScript Entry Point// To run this program, use: `node filename.js`
console.log('Hello, World!');
cotrVarMapAlt
JavaScript Create Map Variable
let ${1:myMap} = new Map([ [${2:'key1'}, ${3:'value1'}], [${4:'key2'}, ${5:'value2'}]]);
cotrFuncAnon
JavaScript Anonymous Function
function(${1:parameters}) { ${2:// Your code here}};
cotrClass
JavaScript Class
class ${1:MyClass} { ${2:// Your code here}}
cotrTypesString
JavaScript String Type
let text = "John Doe";
cotrPrint
JavaScript Print
console.log(${1:'Your message here'});
cotrForLoop
JavaScript For Loop
for (let ${1:i} = 0; $1 < ${2:10}; $1++) { // Your code here}
cotrVarDate
JavaScript Create Date Variable
let ${1:myDate} = new Date(${2:year}, ${3:month} - 1, ${4:day});
cotrVarList
JavaScript Create Array Variable
let ${1:myList} = [${2:'item1'}, ${3:'item2'}];
cotrConst
JavaScript Create Constant
const ${1:myConst} = $2;
cotrTernary
JavaScript Ternary Operator
${1:condition} ? ${2:trueValue} : ${3:falseValue}
cotrNotEqual
JavaScript Not Equal To
!==
cotrVarMultiString
JavaScript Create Multi-Line String Variable
let ${1:myString} = `${2:Line 1}${3:Line 2}${4:Line 3}`;
cotrVarBool
JavaScript Create Boolean Variable
let ${1:myBoolean} = ${2:true};
cotrOperators
JavaScript Mathematical Operators
// JavaScript Mathematical Operators// Addition: +// Subtraction: -// Multiplication: *// Exponentiation: **// Division: /// Modulus (Remainder): %// Increment: ++// Decrement: --// Assignment: =// Addition assignment: +=// Subtraction assignment: -=// Multiplication assignment: *=// Division assignment: /=// Modulus assignment: %=
cotrVarStatic
JavaScript Static Variable
static ${3:myStaticVar} = ${4:value};
// Access the static variable// MyClass.${3:myStaticVar}
cotrGenMap
JavaScript Generate Object Map
const ${1:myMap} = Object.fromEntries( Array.from({ length: ${2:length} }, (_, index) => [`key${index}`, `value${index}`]));
cotrIfElse
JavaScript If Else Statement
if (${1:condition}) { ${2:// Your code here}} else if (${3:condition}) { ${4:// Your code here}} else { ${5:// Your code here}}
cotrTypesInt
JavaScript Int Type
let integer = Math.floor($1);
cotrForOfLoop
JavaScript For…Of Loop
for (const item of ${1:iterable}) { ${2:// Your code here}}
cotrCommentMulti
JavaScript Multi-Line Comment
/* * ${1:Your comment here} */
cotrInterpolate
JavaScript Interpolate String
let text = `Hello, ${1:name}!`;
cotrVarString
JavaScript Create String Variable
let ${1:myString} = "${2:Your string here}";
cotrNow
JavaScript Date Now
new Date()
cotrTypeCheck
JavaScript Type Check
typeof ${1:variable}
cotrTypeConvert
JavaScript Type Conversion
// JavaScript Type Conversion:
// Implicit conversions (JavaScript performs automatically):// - Can be unpredictable, especially with loose equality (==).
// Explicit conversions:// - Number(variable) // Converts to number// - String(variable) // Converts to string// - Boolean(variable) // Converts to boolean// - parseInt(string) // Converts string to integer// - parseFloat(string) // Converts string to floating-point number
// Note:// - Be aware of implicit conversions and use explicit conversions when necessary for clarity and control.
cotrTypesBool
JavaScript Boolean Type
let flag = Boolean($1);
cotrVarTyped
JavaScript Create Typed Variable
let ${1:myVar} = $2; // Note: JavaScript is dynamically typed.
cotrLambda
JavaScript Lambda
const ${1:myLambda} = (${2:parameters}) => ${3:expression};
cotrConcat
JavaScript Concatenate String
let text = 'Hello, ' + ${1:name} + '!';
cotrVarNullable
JavaScript Create Nullable Variable
let ${1:myVar} = null;
cotrGenList
JavaScript Generate Array
const ${1:myList} = Array.from({ length: ${2:length} }, (_, index) => ${3:'item'} + index);
cotrIf
JavaScript If Statement
if (${1:condition}) { ${2:// Your code here}}
cotrStructure
JavaScript Project Structure (High-Level)
// Recommended High-Level JavaScript Project Structure:
// - src/// - Contains the source code of the application.// - Common subdirectories within src include:// - components/ (for UI components in a React/Vue/Angular app)// - utils/ (for utility functions)// - services/ (for API calls and external services interaction)// - assets/ (for images, fonts, and other static assets)
// - public/// - Contains static files like index.html, favicon.ico, etc.
// - tests/ or __tests__/// - Contains test files for unit testing, integration testing, etc.
// - node_modules/// - Contains all the npm packages and dependencies for the project.
// - build/ or dist/// - Contains the compiled and minified production-ready files.
// - config/// - Contains configuration files for build tools, CI/CD processes, etc.
// - docs/// - Documentation for the project.
// - scripts/// - Build scripts, deployment scripts, and other automation scripts.
// Note:// - The actual structure can vary based on the project's needs,// and the tools/frameworks being used (e.g., React, Vue, Angular, etc.).
cotrOperatorsBool
JavaScript Boolean Operators
// JavaScript Boolean Operators// Logical AND: &&// Logical OR: ||// Logical NOT: !// Equality: ==// Strict Equality: ===// Inequality: !=// Strict Inequality: !==// Greater than: >// Less than: <// Greater than or equal to: >=// Less than or equal to: <=
cotrTypes
JavaScript Types
$BLOCK_COMMENT_STARTJavaScript is a dynamically typed language. It does not have static types.
Types in JavaScript include:- Number: for both integers and floating-point numbers- String: for text- Boolean: for true/false values- Object: for key-value pairs- Array: for ordered lists- Function: for executable functions- Symbol: for unique identifiers- null: for absence of value- undefined: for uninitialized variables$BLOCK_COMMENT_END
cotrTypeCompare
JavaScript Type Comparison
// Check if two variables have the same type:if (typeof ${1:variable1} === typeof ${2:variable2}) { // Your code here}
cotrTypesMap
JavaScript Map Type
new Map()
cotrWhileLoop
JavaScript While Loop
while (${1:condition}) { ${2:// Your code here}}
cotrThrow
JavaScript Throw Exception
throw new Error('Your message here');
cotrFunc
JavaScript Function
function ${2:myFunction}(${3:parameters}) { ${4:// Your code here}}
cotrFuncArgs
JavaScript Function Args
// In JavaScript, functions can have arguments with default values.function ${2:myFunction}(${3:arg1}, ${4:arg2} = ${5:defaultValue}) { ${6:// Your code here}}
cotrTypesNum
JavaScript Number Type
let number = $1;
cotrVar
JavaScript Create Variable
let ${1:myVar} = $2;
cotrSwitch
JavaScript Switch Statement
switch (${1:variable}) { case ${2:value1}: ${3:// Your code here} break; case ${4:value2}: ${5:// Your code here} break; default: ${6:// Your code here}}
cotrComment
JavaScript Comment
// ${1:Your comment here}
cotrTypesBoolTrue
JavaScript Boolean True
true;
cotrTypesDate
JavaScript Date Type
Date
cotrTypesList
JavaScript List Type
[]
cotrVarMap
JavaScript Create Map Variable (Object)
let ${1:myObject} = { ${2:'key1'}: ${3:'value1'}, ${4:'key2'}: ${5:'value2'}};
cotrPrintMulti
JavaScript Print Multi
console.log(`${1:Line 1}${2:Line 2}${3:Line 3}`);
cotrFuncArrow
JavaScript Arrow Function
const ${2:myFunction} = (${3:parameters}) => { ${4:// Your code here}};
cotrNull
JavaScript Null Type
null
cotrVarSyntax
Variable Declaration Syntax
// JavaScript Variable Declaration Syntax:
// - var: (Scope: Function or Global)// - Can be reassigned and redeclared within its scope.// - Use with caution due to potential scoping issues.
// - let: (Scope: Block)// - Can be reassigned but not redeclared within its scope.// - Preferred for variables that need to be reassigned.
// - const: (Scope: Block)// - Cannot be reassigned or redeclared.// - Use for values that should remain constant.
// Note:// - Use 'let' for most variable declarations.// - Use 'const' for values that should not change.
cotrVarNum
JavaScript Create Number Variable
let ${1:myNumber} = ${2:0};
cotrEqual
JavaScript Equal To
===
cotrTypesDynamic
JavaScript Dynamic Type
// There is no specific syntax for declaring a variable with a dynamic type in JavaScript.
cotrFuncArgsNamed
JavaScript Function Named Args
function ${2:myFunction}({${3:arg1}, ${4:arg2}}) { ${5:// Your code here}}