Programming Tips - javaScript: get first character in a string

Date: 2023jan26 Language: javaScript Q. javaScript: get first character in a string A. There are many ways, but I think these are the cleanest:
const mystr = "hello"; const first = mystr.substr(0,1); const first = mystr.charAt(0);
Or a function:
firstChar(s) { if (typeof(s) != 'string') return undefined; if (s.length == 0) return undefined; return s.charAt(0); }