Skip to content

Instantly share code, notes, and snippets.

@mindbrave
Created October 4, 2018 12:48
Show Gist options
  • Save mindbrave/8218a25de6a7ba1372a221e68fa27ac6 to your computer and use it in GitHub Desktop.
Save mindbrave/8218a25de6a7ba1372a221e68fa27ac6 to your computer and use it in GitHub Desktop.
Why declarative > imperative. Simple example.
<html>
<head>
<title>Declarative!</title>
</head>
<body>
<h1>Declarative!</h1>
</body>
</html>
const html = document.createElement('html');
const head = document.createElement('head');
const title = document.createElement('title');
const body = document.createElement('body');
const h1 = document.createElement('h1');
const titleText = "Imperative!";
title.textContent = titleText;
h1.appendChild(document.createTextNode(titleText));
head.appendChild(title);
body.appendChild(h1);
html.appendChild(head);
html.appendChild(body);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment