you can pass parameters to arrow functions as well as shown in the following demo, these functions are only meant to be used once where normal functions can be re-used.
in this exercise i will take a function variable and write it in one line using the arrow function
This shows how you can lock an object so its content cannot be modified. if you comment out the line Object.freeze(my_object); it will allow it to be modified again.
a const means that you cannot re-declare the variable name, but you can still mutate an array content that is declared as a const. so you can see in the following example that even though the array is..
this will return an australian state code based on the postcode, so you can enter a valid postcode and see which state it belongs too. e.g: 2000 should return NSW
This example uses let and const rather than just vars, let can only be declaired once rather than overwritten like vars and const is a read only variable so it cant be changed.
Using let rather than var and use strict can avoid some overwriting of variables i will write a function here that shows how let throws an error. This function now gives an error in the console. Uncau..
I actually find if then statements much easier to read than these ones, but these seem more efficient.
this statement can be used instead of if this else that statements. to me it makes it look a bit more complex when reading it. this is the basic syntax. condition ? statement-if-true : statement-if-fa..
This is the same as the parseint function, but you can also specify a base for the number which can be between 2 - 36. 2 is binary. Zeros and Ones. I think base 10 is the normal numbering system, but ..
this function uses the parseInt function to return a proper integer or an error code if it can't. So this demo should return NaN for the Not an Int (x1235) and The int for the 00001235. I think that N..
My testing for generating a random whole number within a range... 🤞 While the solution here works, it just loops until it gets a random number that is lower than the max, so not sure if this is th..
this will split the string into an array based on the spaces inbetween words. you can split it based on any character, for example if you had words in csv comma format you could use the second example..
this will get the current address add it to a variable and show it on the result element
For a while i have been using frameworks for their easy grid systems, like foundation and bootstrap. I guess this is a bit lazy and very bloated as you are loading the full css library and using about..
this is a template that i use while testing flat html files, if you add it to a server it will live reload. this does seem to cause issues depending on the site that is is used on, like reloading all ..
generate a random whole number function with test buttons
generate a random fraction and add it to result when clicking a button
my solution to the FCC Basic js Profile Lookup, with added results area and button to run the function. json, array
using xcopy and a loop i found this is a good way to make sure that changes in one file make their way across to another location using a windows batch file. this one loops every 5 seconds, i think yo..
showing how to use a do while loop, i don't use these ones very often usually just a for loop.
good if you have inline styles you want to remove using regex find and replace. in sublime press ctrl + H to do find and replace then paste in the style="([^
this is the setting to remove the automatic p tag's when pressing enter and forces the use of br tags instead which can also be toggled, if you dont want it to add anything.
you can add a data attribite and target it with css using the following demo
showing an example of chevron toggles kinda like a manual accordion
this is good if you want to change a form checkbox with the default and show a fancy tick or something else, this will still check the checkbox so will work normally as the form element
good if you have apache and access to htaccess file to redirect requests to https version of the site. this one also includes a rewrite to index.php so if you don't need this remove the last line.
this function returns the type of item, array object string number etc
here is a solved version of the card counting function from free code camp you can test it using console log.
this can be used if you have several outcomes where the return value will be the same by omitting the break from the cases before the final
This shows an example using the switch to select multiple options in a function, you can return from the switch with break, or you can end the whole function with return.
this function will return the score name depending on the par and strokes for golf
you can use the typeof operator to check what kind of variables you have.
here is an example showing a variable defined within a function showing how it becomes a global variable if not defined with var
unshift is the opposite of push where push adds to the end of an array unshift will add to the start of the array.
like pop but shift does the 1st element in an array
this is a version of a dom ready or document ready that does not require jquery
a one liner to add a class name to an element with a specific id, for this to run it seems to need a document ready.