Python uses Show In this post I'll show you can use snake case on the backend and camel case
on the frontend, with the help of the the The problem: out of place naming stylesLet's say you've got some Django code that presents an API for a
And you've also got some JavaScript code that talks to this view:
The problem occurs when you try to use the data fetched from the backend and it is using the wrong variable naming style:
This usage of snake case in JavaScript is a little yucky and it's a quick fix. The solution: install more JavaScript librariesHint: the solution is always to add more dependencies. To fix this we'll install snakeize and camelize using npm or yarn:
Then you just need to include it in your frontend's API functions:
Now we
can use
That's it! Hope this helps your eyes a little. Does JavaScript use snake case or camelCase?Snake case (also referred to as underscore case) is when all the letters of the word are lower case but delimited by an underscore. We seldom use the snake case coding convention in C-style languages like Java, JavaScript, and TypeScript.
Should JavaScript variables be camelCase or underscore?Most every JS variable you write will be in camelCase. Since variables can hold anything and can be changed easily, we use conventions to give more information to other developers, Like using 'is' or 'has' to prefix variables that hold booleans. And using all caps for variables that hold values that should never change.
Why we use camelCase in JS?When multiple words are used to form a variable, camel case joins those words together, without any white space, and delineates the start of each new word with a capital letter.
What is camel case in JavaScript?Camel case is the practice of writing phrases such that each word or abbreviation in the middle of the phrase begins with a capital letter, with no intervening spaces or punctuation. For example, Concurrent hash maps in camel case would be written as − ConcurrentHashMaps.
|