Skip to main content

Posts

Showing posts with the label javascript

JavaScript Best Practices: Tips & Tricks to Level Up Your Code

Learning new things everyday is part of what makes being a rational human being great. And as developers, it is part of our job to learn new things continuously, whether or not these things are from positive learning experiences. In this tutorial, I will point out a few important JavaScript best practices so you don’t have to learn it the hard way. Get ready to level to your code! 1. Avoid polluting the global scope Declaring variables is a lot of fun. Sometimes, you may declare global variables even if you don’t want to. In today’s browsers, the global variables are stored in the window object. So, since there’s a lot of stuff going on there, you may override default values. Let’s suppose you have an HTML file which contains a <script> tag containing (or which loads a JavaScript file containing): var foo = 42 ; console . log ( foo ) ; This will obviously output 42 in the console. But since the code is not executed in a function, the context will be the glob...

Easy way to add a dark theme on your website

What is a dark theme? A dark theme displays dark color in the maximum of the UI, reducing strain in our eyes. Recently, a dark theme is a common trend, that can be seen on most websites and apps. Here in this blog, I am going to share one of the easy ways to add a dark theme when we click a button. Turn Your webpage from here: To here: Our main concern is to change the theme, so we are not focusing on beauty and other functionality. HTML We are just creating a button, so we need just a single button tag in the HTML file. <button id= "myBtn" > Push Me </button> CSS The below code is used to create the basic light theme on the page. * { margin : 0 ; padding : 0 ; border : none ; box - sizing : bor...

Solid - The best JavaScript UI library?

A while ago, I wrote a post on some of the most important advantages of Svelte. Back then, the framework had just received a major update, and it was quite a hot topic to cover. Now, after the dust has settled, Svelte still has a lot going for it, but it also has some drawbacks that previously went unnoticed. I don't want to rant over these small issues because that's not the point of this article, and besides - I really like Svelte! But for your information, these are: TypeScript support - although it's been added recently, it wasn't there at the time Svelte exploded in popularity. Thus, most of its still small, but very important for the framework ecosystem will most likely not support it. Syntax differences - Svelte feels good when you get used to it, but because of its compiler-bas...