We often encounter a situation where a property we're trying to extract doesn't exist in the object/array, resulting in a TypeError (while destructuring nested objects) or being set to undefined. While destructuring we can set a default value, which it will fallback to, in case of it not being found...
We are not limited to destructuring an object/array, we can destructure a nested object/array.
Nested Object Destructuring
var obj = {
a: {
c: 1,
d: 3
},
b: 2
};
var {
a: {
c: x,
d: y
},
b: z
} = obj;
console.log(x, y, z); // 1,3,2
Nested Array ...
\documentclass{article}% or book, report, ...
\begin{document}
See \cite{citeA} or \cite{citeB} or \cite{citeA, citeB}.
\begin{thebibliography}{x}
% \bibitem{<biblabel>} <citation>
\bibitem{citeA}
{\scshape Author, A}, {\itshape A title}, Journal of So-and-So, 2000....
round() tie breaking
In Python 2, using round() on a number equally close to two integers will return the one furthest from 0. For example:
Python 2.x2.7
round(1.5) # Out: 2.0
round(0.5) # Out: 1.0
round(-0.5) # Out: -1.0
round(-1.5) # Out: -2.0
In Python 3 however, round() will retur...
adduser command adds a user to the system. In order to add a new user type:
sudo adduser <user_name>
example:
sudo adduser tom
After typing the above command, you will be prompted to enter details about the new user, such as new password, user Full name, etc.
Below is the information ...
using System;
namespace TypeConversionApplication
{
class ExplicitConversion
{
static void Main(string[] args)
{
double d = 5673.74;
int i;
// cast double to int.
i = (int)d;
Console.WriteLine(i);
Cons...
An Interface's function known as a "contract" of functionality. It means that it declares properties and methods but it doesn't implement them.
So unlike classes Interfaces:
Can't be instantiated
Can't have any functionality
Can only contain methods * (Properties and Events are metho...
Don't you hate it when interfaces pollute you class with too many members you don't even care about? Well I got a solution! Explicit Implementations
public interface IMessageService {
void OnMessageRecieve();
void SendMessage();
string Result { get; set; }
int Encoding { get; se...
Dictionary<TKey, TValue> is a map. For a given key there can be one value in the dictionary.
using System.Collections.Generic;
var people = new Dictionary<string, int>
{
{ "John", 30 }, {"Mary", 35}, {"Jack", 40}
};
// Reading data
Console.Wri...
To register your device for push notifications, add the following code to your AppDelegate file in didFinishLaunchingWithOptions method:
Swift
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
// Override point for c...
Strict-Transport-Security: max-age=31536000; includeSubDomains
Strict-Transport-Security is a promise to the browser that all future requests to this domain will be secure.
For the future time period max-age:
All outgoing HTTP requests from the browser will be converted to HTTPS on the client...
Strict-Transport-Security: max-age=31536000; includeSubDomains; preload
HSTS is activated only after a successful HTTPS request to the server with a valid certificate. There is still a risk of a first-time user accessing the site, at which point a Man-in-the-Middle attack is possible.
To make th...
Note: Before upgrading your Rails app, always make sure to save your code on a version control system, such as Git.
To upgrade from Rails 4.2 to Rails 5.0, you must be using Ruby 2.2.2 or newer. After upgrading your Ruby version if required, go to your Gemfile and change the line:
gem 'rails', '...
Unlike show.bind when using if.bind the element will be removed from the page if the supplied binding value is false or added into the page if the value is true.
export class MyViewModel {
isVisible = false;
}
<template>
<div if.bind="isVisible"><strong>If ...
Create a server.js file with the following contents:
'use strict';
const Hapi = require('hapi');
// Create a server instance
const server = new Hapi.Server();
// Specify connections (server available on http://localhost:8000)
server.connection({
port: 8000
});
// Add a route
...
The following are the steps to start an Eclipse remote debugger. This is useful when the application is not started from a server instance within Eclipse. This feature is really powerful and can also help debugging code which resides in the test or production environment. Let's have a look at the se...
Setup your view controller to manage editing of text for the text field.
class MyViewController: UITextFieldDelegate {
override viewDidLoad() {
super.viewDidLoad()
textField.delegate = self
}
}
textFieldShouldReturn is called every time the return butto...