3+ Ways to Write Clean Code in JavaScript

  Рет қаралды 9,266

dcode

dcode

Жыл бұрын

View the Starting Code:
dcode.domenade.com/tutorials/...
Coding is an art, so why not make it as clean as possible? In this video I go over 3 techniques I like to implement to help make my JavaScript code easier to read and extend upon.
🏫 My Udemy Courses - www.udemy.com/user/domenic-co...
🎨 Download my VS Code theme - marketplace.visualstudio.com/...
💜 Join my Discord Server - / discord
🐦 Find me on Twitter - / dcodeyt
💸 Support me on Patreon - / dcode
📰 Follow me on DEV Community - dev.to/dcodeyt
📹 Join this channel to get access to perks - / @dcode-software
If this video helped you out and you'd like to see more, make sure to leave a like and subscribe to dcode!
#dcode #javascript

Пікірлер: 27
@dcode-software
@dcode-software Жыл бұрын
OK, I did mess up the "if statement" regarding the hours and light/dark mode. Sorry about that. It probably should be an OR instead.
@marcinzale
@marcinzale Жыл бұрын
Very good advices. Thank you.
@pulserudeus7968
@pulserudeus7968 Жыл бұрын
Amazing stuff Dom! We need more of this sheesh 🔥 Thanks man for giving out valuable content as always🥂
@mrTiberiuDubau
@mrTiberiuDubau Жыл бұрын
DOM IS BACK!!!! 🙂
@EnzoAuditore
@EnzoAuditore Жыл бұрын
Thank you for this.
@beinyourguard
@beinyourguard Жыл бұрын
really cool!
@danielfrimu1996
@danielfrimu1996 9 ай бұрын
what theme are you using??
@mofmse
@mofmse 9 ай бұрын
I try to avoid concatenate. const capitalize = function(name, locale = 'en') { return name.replace(/^./, name.at(0).toLocaleUpperCase(locale)); }
@saschamajewsky7990
@saschamajewsky7990 Жыл бұрын
I would have written something like: function getThemeColors() { const currentHour = new Date.getHours(); const darkTheme = { textColor: "#fff", backgroundColor: "#222222"}; const lightTheme = { textColor: "#222222", backgroundColor: "#fff"}; return (currentHour > 20 && currentHour < 7) ? darkTheme : lightTheme; }
@christian-schubert
@christian-schubert Жыл бұрын
Also numbers.forEach(number => 12 % number === 0 && console.log(`${number} is a factor of twelve!`)); 😎 ...if it's really the shortening of our codebase that we're after. Might not be as performant though
@hassansyed6087
@hassansyed6087 Жыл бұрын
I like it. It's clean
@castletown999
@castletown999 Жыл бұрын
Thought provoking as usual - thank you. But I do disagree with one of your solutions. I was taught that functions should have just one entry point and one exit point. Why? Imagine say you have a function that looks in a file for something. On entry it opens the file, and on exit it closes it again. If you exit in the middle you could forget to close it and cause a resource leak. In general a function on entry has some setup to do, and on exit knocks it down again. Returning form the middle is just asking for trouble. A maintainer may add something towards the end of the function, not realizing that it can exit earlier and not run the new code.
@DroidNexus
@DroidNexus Жыл бұрын
Dcode tenho uma dúvida. No appgyver Com a api da xano eu criei um aplicativo e adicionei dois métodos de login, um para cliente e outro para empresas, com isso eu criei duas tabelas de base de dados na database, uma para a conta pessoal e outra para conta da empresa. Até aí tudo bem. Tudo da parte de cadastro funcionou. Mas eu queria criar uma data base média para fazer upload de imagem do aplicativo, Da foto de perfil de usuário. MAS ISSO PARA CADA USUÁRIO. para as duas contas tanto de empresa quanto de usuário eu queria que eles fizessem upload de imagem na mesma database, de novo até aí tudo bem. O PROBLEMA É que quando eu quero que ele busque a media_id do id da imagem na database ele precisa do token de autenticação, o problema é que toda a vez quando tento, dá acesso não autorizado no aplicativo. Ele não pega o token de autorização da conta empresa, Isso quando eu faço pela conta da empresa! Só pega a do cliente que foi a que eu fiz primeiro. Queria criar um aplicativo duas databases diferentes uma para empresa e uma para o cliente. Mas quando eu quero que ele busque id pra colocar na tabela da média ele da erro de autenticação access unaltorizhed.
@magicorpse
@magicorpse Жыл бұрын
Sorry for the question, but why at 13:15, there is not need to write names.map(name => capitalize(name)); is it a javascript shortcut? thanks.
@pgd724
@pgd724 Жыл бұрын
I was thinking the same thing!
@dcode-software
@dcode-software Жыл бұрын
Using the parenthesis means that you're calling function. If you pass in "capitalize" without the parenthesis, it's passing a reference to the function (which is what we want)
@magicorpse
@magicorpse Жыл бұрын
@@dcode-software Thanks for the reply and the video, dcode.
@suelingsusu1339
@suelingsusu1339 Жыл бұрын
👌👌🙏🙏👍👍🌹🌹🖖🖖🖖🖖
@maxdevjs3457
@maxdevjs3457 Жыл бұрын
Am I wrong or should be "7 < currentHour)" (eventually "currentHour > 7)") ?
@Fatali.Fataliyev
@Fatali.Fataliyev Жыл бұрын
currentHour < 7 explanation: Current hour less than 7.
@maxdevjs3457
@maxdevjs3457 Жыл бұрын
@@Fatali.Fataliyev ​ I guess that that && in reality is a || 🤔
@Fatali.Fataliyev
@Fatali.Fataliyev Жыл бұрын
@@maxdevjs3457 In this case?
@maxdevjs3457
@maxdevjs3457 Жыл бұрын
@@Fatali.Fataliyev yes. If I am not missing something, currentHour can not be less than 7 and, simultaneously, to be greater than 20. Right...?
@Fatali.Fataliyev
@Fatali.Fataliyev Жыл бұрын
@@maxdevjs3457 Yes.
@andrew_ortega89
@andrew_ortega89 Жыл бұрын
“currentHour > 20 && currentHour < 7” is how we say it. In a program, however, this will always be false. But I see the point anyway, thank you!
@dcode-software
@dcode-software Жыл бұрын
Yep I messed this up. I've added a pinned comment :) thanks.
@Pareshbpatel
@Pareshbpatel Жыл бұрын
Thanks for the Clean-Code tips, Dom! {2023-10-21}, {2024-03-25}
12 Things Every JavaScript Developer Should Know
14:29
dcode
Рет қаралды 10 М.
Why Signals Are Better Than React Hooks
16:30
Web Dev Simplified
Рет қаралды 457 М.
Homemade Professional Spy Trick To Unlock A Phone 🔍
00:55
Crafty Champions
Рет қаралды 58 МЛН
Children deceived dad #comedy
00:19
yuzvikii_family
Рет қаралды 6 МЛН
Super gymnastics 😍🫣
00:15
Lexa_Merin
Рет қаралды 108 МЛН
How Senior Programmers ACTUALLY Write Code
13:37
Thriving Technologist
Рет қаралды 1,4 МЛН
5 POWERFUL JavaScript Events You Didn't Know
10:43
dcode
Рет қаралды 15 М.
3 Tips To Write Clean Code (from an ex-Google software engineer)
17:12
Clément Mihailescu
Рет қаралды 191 М.
Common JavaScript Mistakes and How to Avoid Them
18:48
dcode
Рет қаралды 6 М.
7 MUST KNOW JavaScript Tips and Tricks
8:58
dcode
Рет қаралды 20 М.
How to Write Neatly + Improve Your Handwriting
5:50
Charm
Рет қаралды 25 МЛН
How principled coders outperform the competition
11:11
Coderized
Рет қаралды 1,6 МЛН
Premature Optimization
12:39
CodeAesthetic
Рет қаралды 765 М.
5 Real Life Examples of Array Reduce in JavaScript
12:47
Homemade Professional Spy Trick To Unlock A Phone 🔍
00:55
Crafty Champions
Рет қаралды 58 МЛН