📒
Notes
Cloud ComputingData Science/AIGame Development
  • Home
  • Big O
  • Data Structures & Algorithms
    • Data Structures
      • Array
      • Stack
      • Queue
      • Linked List
      • Binary Tree
    • Algorithms
      • Searching
      • Sorting
      • Graphs
        • Searching
        • Minimum Spanning Tree
        • Shortest Path Algorithms
      • String Algorithms
  • Object Oriented Programming
  • Languages
    • HTML/CSS
      • CSS
    • C++
    • C#
      • Types
      • Keywords
        • Modifiers
          • Access Modifiers
        • Method Parameters
      • Operators and Expressions
      • Collections
      • Constructors
      • Delegates
      • Indexers
      • Concepts
      • Features
        • LINQ
          • Operators
          • Working with Data
          • Methods
          • Resources
        • Asynchronous Programming
        • Reflection
    • Dart
    • GraphQL
    • JavaScript
      • Variable and Parameter
      • Built-in objects
        • Array
        • Built-in Functions
      • Functions
      • Classes
      • Prototype
      • Libraries
        • jQuery
        • React
          • Components
          • State and Lifecycle
          • Hooks
            • useState
            • useEffect
          • Resources
      • Testing Framework
      • Web APIs
    • Kotlin
      • Basics
    • Python
      • Basics
      • Data Structures
      • Functions
      • Resources
        • Flask
    • SQL
      • Basics
      • Operators
      • JOINs
      • Aggregations
      • Subqueries
      • Views
      • Functions
        • Window Functions
      • Stored Procedures
      • Performance Tuning
      • Extras
    • Resources
  • 🌐Web Frameworks
    • Angular
      • Templates
      • Directives
        • Attribute Directives
        • Structural Directives
    • ASP.NET
      • Fundamentals
        • Dependency Injection
        • Middleware
        • Session & State Management
      • Web apps
        • MVC
          • Controllers
            • Filters
          • Models
            • Model Binding
            • Model Validation
          • Views
            • Tag Helpers
            • View Components
          • Features
        • Client-side development
      • Web APIs
        • Controller-based APIs
        • Minimal APIs
        • OpenAPI
        • Content Negotiation
      • SignalR
      • Host and Deploy
        • IIS
      • Security
    • Django
      • The Request/Response Cycle
    • Terminologies
      • Web Server
        • Internet Information Services
    • Resources
  • 📱App Frameworks
    • Introduction
      • Resources
    • Xamarin
      • Lifecycle
      • Custom Renderers & Effects
      • Behaviors
      • Triggers
      • Gestures
      • Commands
      • Dependency Service in XF
      • Libraries
      • Showcase
    • .NET MAUI
      • Controls
      • Navigation
      • Storage Options
  • Multi-Platform Frameworks
    • .NET
      • .NET Framework
        • ADO.NET
        • WCF
      • Fundamentals
        • Logging
        • Testing
      • Advanced
        • Asynchronous Programming
        • Parallel Programming
        • Threading
        • Memory Management
          • Garbage Collection
    • Flutter
  • Object-Relational Mappers
    • Entity Framework
      • Application Models
      • Configuration
      • Setting Up
      • Advanced
  • Databases
    • Introduction
      • DBMS Architecture
      • Normalization
      • Database Transaction Models
    • Relational Databases
      • Microsoft SQL Server
        • Basics
        • Functions
        • Stored Procedures
        • Error Handling
        • Log Shipping
        • Querying and Manipulating JSON data
        • Statements
        • Topics
        • Extras
    • Non-Relational Databases
      • MongoDB
      • Redis
        • Data Structures
        • Introduction
        • Managing Database
  • Tools
    • Version Control
      • Git
        • Setup and Config
        • Basics
          • Sharing and Updating Projects
        • Resources
      • Perforce Helix
    • GitHub
    • Powershell
  • Software Development
    • Software Development Life Cycle
    • Software Design Patterns
      • GoF Design Patterns
      • Architectural Patterns
        • MVC
        • MVVM
        • N-tier Architecture
        • Onion Architecture
        • Data Transfer Objects
      • CQRS
    • Software Design Principles
      • S.O.L.I.D. Priniciple
  • System Design
    • Topics
      • Load Balancing
  • Topics
    • JWT
    • Caching
      • Static vs Dynamic Caching
    • OSI model
      • HTTP
    • Glossary
    • API
      • SOAP
      • REST
    • Microservices
    • WebHooks
    • Practice
    • Operating Systems
      • Windows
    • Architecture
  • 🔖Bookmarks
  • 🔗Resources
Powered by GitBook
On this page
  • Destructuring
  • default parameters
  • Rest Parameter (is like varargs)
  • Spread Parameter
  • Template Literals

Was this helpful?

  1. Languages
  2. JavaScript

Variable and Parameter

Keyword
Scope
IsMutable

var

function

yes

let

block

yes

const

block

no

if (true) {
    let a = 40;
    console.log(a); // 40
}
console.log(a);     // undefined.
const DOB = '10.05.1998';
DOB = '13.05.1998';             // error, can't reassign the constant

const Languages = ['Python', 'C#'];
Languages = "Java";              // error
Languages.push("JavaScript");    // correct
console.log(Languages);          // ['Python', 'C#', 'JavaScript']
let a = 50; let b = 100;
if (true) {
    let a = 60;
    var c = 10;
    console.log(a/c);         // 6
    console.log(b/c);         // 10
}
console.log(c);                 // 10
console.log(a);                 // 50

Destructuring

Destructuring Arrays

let x = 3;
let y = 2;

[x,y] = [y,x];

//x=2
//x=3 

Reference

Destructuring Objects

let test = {
    firstName: "John",
    lastName: "Doe"
};

let {first, last} = test;

//first = "John"
//last = "Doe"

Reference

default parameters

var doWork = function(name = "John"){
    return name;
};

var result = doWork();
//var result = doWork(undefined);

//result = "John"

//var result = doWork("Scott");
//result = "Scott"

Rest Parameter (is like varargs)

  • Rest parameter allows the functions to accept an indefinite number of arguments as as array.

  • Rest parameter should appear after any regular parameters.

let doWork = function(name, ...numbers){    //rest parameter
}
function greet(...names){
    names.forEach(name => console.log('Hi, ' + name));
}

greet('Rose', 'Mary', 'Marlo')
//Hi, Rose
//Hi, Mary
//Hi, Marlo
function greet(message, ...names){
    console.log(message);
    names.forEach(name => console.log('Hi, ' + name));
}

greet('Hello, World!', 'Rose', 'Mary', 'Marlo')
//Hello, World!
//Hi, Rose
//Hi, Mary
//Hi, Marlo

Spread Parameter

  • Spread parameter is the exact opposite of how Rest parameter works.

  • It allows a function to take an array as as argument and then spread out its elements so that they can be assigned to individual parameters.

let doWork = function(x,y,z){
    return x+y+z;
};

var result = doWork(...[1,2,3])    //spread parameter

// x=1  y=2  z=3    result = 6

var a = [4,5,6]
var b = [1,2,3,...a,7,8,9]        //spread parameter

//b = [1,2,3,4,5,6,7,8,9]
function greet(person1, person2){
    console.log('Hi, ' + person1 + ' and ' + person2);    //Hi, John and Jane
}

let names = ['John', 'Jane');
greet(...names);                // spread parameter

Template Literals

let username = "john";
let url = `https:\\github.com\${username}`;

//url = https:\\github.com/john-***********/*-///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
console.log(a);    // error
var a;             // undefined
  • JavaScript always hoists the declaration of any variable at the top so even if in code it appears to be after calling the variable it won't give an error.

PreviousJavaScriptNextBuilt-in objects

Last updated 3 years ago

Was this helpful?

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Destructuring_assignment#array_destructuring
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Destructuring_assignment#object_destructuring
Front End Web Development: Get Started | Pluralsight
Logo