How to create a GUID / UUID

UUIDs (Universally Unique IDentifier), also known as GUIDs (Globally Unique IDentifier), according to RFC 4122, are identifiers designed to provide certain uniqueness guarantees. While it is possible to implement RFC-compliant UUIDs in a few lines of JavaScript code (e.g., see @broofa’s answer, below) there are several common pitfalls: Invalid id format (UUIDs must be of the form … Read more

JavaScript string newline character?

I’ve just tested a few browsers using this silly bit of JavaScript:  Run code snippetExpand snippet IE8 and Opera 9 on Windows use \r\n. All the other browsers I tested (Safari 4 and Firefox 3.5 on Windows, and Firefox 3.0 on Linux) use \n. They can all handle \n just fine when setting the value, though IE and Opera … Read more

Is there a difference between /\s/g and /\s+/g?

In the first regex, each space character is being replaced, character by character, with the empty string. In the second regex, each contiguous string of space characters is being replaced with the empty string because of the +. However, just like how 0 multiplied by anything else is 0, it seems as if both methods strip spaces in exactly the … Read more

How to add jQuery code into HTML Page

1) Best practice is to make new javascript file like my.js. Make this file into your js folder in root directory -> js/my.js . 2) In my.js file add your code inside of $(document).ready(function(){}) scope. 3) add your new js file into your html

Can’t resolve module (not found) in React.js

The way we usually use import is based on relative path. . and .. are similar to how we use to navigate in terminal like cd .. to go out of directory and mv ~/file . to move a file to current directory. In your case, App.js is in src/ directory while header.js is in src/components. To import you would do import Header from ‘./components/header’. This roughly translate to in my current directory, find the components folder that … Read more