This is not ordinary question but it's also not opinion-based, it's more about the standards and the right way of writing JS code. I admit, I'm a total noob in JavaScript, I do not have experience with this language but since it is necessary for the project I'm working on - I had no other choice but to learn a bit about it :P The most basic of things, took me quite some time so I just want to know if the code is written the right way or not. That way I could understand what I've done wrong and learn from it. The reason I'm asking whether it's right or not, instead of checking it myself is because everything work as it supposed to so I've no idea whether I've done it the right way or at least in a valid way.My JavaScript code;if(isMobile) { var currentProtocol = window.location.protocol + '\/\/'; var currentHostname = siteHostname; var currentPath = window.location.pathname; window.location.href = currentProtocol+mobileHostname+currentPath;}function goBack() { window.history.back()}$('a[aria-controls=*]').click(function (e) { e.preventDefault();})$('.close').click(function (e) { e.preventDefault();})$(function (e) { $('[data-toggle=tooltip]').tooltip(); $('[data-toggle=popover]').popover(); $('[aria-controls=*]').tab('show');})function hideCookieNotice() { $('#cookie-notice').addClass('hidden');}$('#cookie-notice-close').click(function (e) { document.cookie='acgcookie=0;path=.'+siteHostname+';expires='+(new Date(+new Date()+157785e6)).toGMTString(); hideCookieNotice();})if (document.cookie.search('acgcookie=0') !== -1) { hideCookieNotice();}var elementHelper = {  /* ==========================================================================  Block Types and Elements ========================================================================== */ notificationDiv: '<div class=\side-notifications\>', /* ==========================================================================  Buttons ========================================================================== */ closeButton: '<button type=\button\ class=\close\><span class=\fa fa-close\ aria-hidden=\true\></span></button>', /* ==========================================================================  Closing Tags ========================================================================== */ closeDiv: '</div>', /* ==========================================================================  Icon Types ========================================================================== */ icon: function (type) {  function newIcon(type) {   if (type == 'info')   {    return 'info-circle';   }   else if (type == 'info2')   {    return 'info-circle2';   }   else   {    return 'Error';   }   return type;  }  theIcon = newIcon(type);  return iconConstruct(theIcon);  function iconConstruct(icon) {   return '<i class=\fa fa-' + icon +'\></i>';  } }}function newNotification(outputMessage) { html = elementHelper.notificationDiv + elementHelper.closeButton + elementHelper.icon('info') + ' ' + outputMessage + '.' + elementHelper.closeDiv; $(html).hide().appendTo('#side-block').fadeIn('slow');}function printLog(outputLog) { console.log(outputLog);}function sendDismiss(e) {  var form_data = ''; var outputMessage = ''; var outputLog = ''; form_data = {  username: userName,  csrfToken: csrf,  type: e[0],  id: e[1],  is_ajax: '1' }; $.ajax({  type: 'POST',  url: 'test.php',  data: form_data,  success: function (response) {   if (response == 'success') {    outputMessage = '<strong>Success:</strong> username=' + form_data['username'] + ', csrf=' + form_data['csrfToken'] + ', type=' + form_data['type'] + ', id=' + form_data['id'];     outputLog = 'Success';    newNotification(outputMessage);    printLog(outputLog);   }   else if (response == '') {    outputMessage = 'Empty';    outputLog = 'Empty response';    newNotification(outputMessage);    printLog(outputLog);   }   else {    outputMessage = response;    outputLog = response;    newNotification(outputMessage);    printLog(outputLog);   }  },  error: function () {   outputMessage = 'Error';   outputLog = 'No response';   newNotification(outputMessage);   printLog(outputLog);  } });  return false;}function changeLang(siteLang) {  document.cookie='acglang='+siteLang+';path=.'+siteHostname+';expires='+(new Date(+new Date()+157785e6)).toGMTString(); var form_data = ''; var outputMessage = ''; var outputLog = ''; form_data = {  username: userName,  csrfToken: csrf,  lang: siteLang,  is_ajax: '1' }; $.ajax({  type: 'POST',  url: 'test.php',  data: form_data,  success: function () {   outputLog = 'Successfully changed site language to ' + siteLang;   printLog(outputLog);  },  error: function () {   outputMessage = 'Error, failed to change site language to ' + siteLang + '.<br />Please contact Support and report this error.';   outputLog = 'Error';   newNotification(outputMessage);   printLog(outputLog);  } });   return false;}function closeIt(e){ $( this ).parent().fadeOut( slow );}$(#side-block).on('click', button.close, closeIt);$(function (e){ $(.close.send-data).click(function(n){  var e = new Array($(this).data(type), $(this).data(id));  sendDismiss(e); });})I did not include the actual mobile device detection because I did not write it myself, I found it on StackOverflow.Also in my HTML doc, the following variables are set;  var siteHostname  =  {siteHostname};  var mobileHostname  =  {$mobileHostname};  var userName   =  {userName};  var csrf    =  {};
Create new elements, simple notification constructor, send data when a notification is dismissed, etc
javascript