Code Snippets Cookies

Javascript Cookies

In this code snippet, we’ll learn how to add/get cookies with Javascript. Cookies allow a website to store information about a user in the browser. This way if the site refreshes or the user leaves and comes back later the data can be preserved. Cookies also get sent along with requests to the server. A server can give the browser a session cookie after the user logs in. This way every time the user sends something to the server it can just check for a valid session to make sure the user is authorized to perform a certain action.

Code Snippets Timer

Javascript Timer

In this code snippet, we’ll learn how to use timers in Javascript. Timers can be used to execute code at certain intervals. When we make a timer we need to specify the function that will be called on each tick and the interval length in milliseconds. We’ll also take a look at delays which opposed to timers only run

Code Snippets Browser Object Model

Javascript Browser Object Model

In this code snippet, we’ll learn how to access the browser object model(BOM) with Javascript. We can use the BOM to interact with the browser itself and get information like screen resolution, window size, OS, language, … We can also open/close windows/tabs, navigate back/forward in history.

Code Snippets jQuery

Javascript jQuery

jQuery is a library that makes working with javascript a bit easier and quicker. It’s not as popular or needed these days because of all the js frameworks. But it’s still present on a lot of older code. Also, I think it’s useful if you are making a smaller project and don’t need the features and complexity of a js framework.

Code Snippets AsyncAwait And Promises

Javascript Async/Await And Promises

In this code snippet, we’ll learn about async/await and promises in Javascript. Promises allow us to execute code asynchronously. When we make a promise we define what code it will execute. When it’s done the then() function is used to execute any further code(process results from the promise). Async and await keywords make working with promises easier. If any value is returned from an async function it will be returned as a promise which can be awaited with the await keyword.

Code Snippets Callbacks

Javascript Callbacks

In this code snippet, we’ll learn about callbacks in Javascript. Callbacks are nothing more than function pointers passed as an argument into another function to be then called from within that function. This example might seem a bit useless but the concept of callbacks becomes much more useful when we start dealing with asynchronous behavior. Like for example when making an API call.

Code Snippets Events

Javascript Events

In this code snippet, we’ll learn about events in Javascript. We can add and subsequently remove event listeners(of different types: click, change, mouseenter, …) to any element of our choosing. These event listeners will wait for the specified event(like clicking on an element) to occur. When finally it does the event listener will call/execute the code we specified beforehand. 

JS Code Snippets DOM Manipulation

Javascript DOM Manipulation

In this code snippet, we’ll learn how to manipulate the DOM with Javascript. When you open up a web page the browser will parse the HTML and CSS. Then it will build a DOM(data object model) from the parsed data. Finally, it will render it to display the web page. Javascript can be used to dynamically change the DOM. We can do that by getting elements(by tag, id or class) and then modifying, adding or removing them.

JS Code Snippets Closures

Javascript Closures

In this code snippet, we’ll learn about closures in Javascript. A closure is simply a function within a function. With this, we can achieve variable encapsulation. In other OOP languages, this would be done by making a private property inside a class. This way the variables inside are isolated and protected from the global space.

Advertisment ad adsense adlogger