What is Kebab Case ?

Last Updated On Thursday 9th Sep 2021

Kebab-case refers to a programming variable naming convention in which a developer replaces spaces between words by a dash.

For Example

Kebab case: “the-quick-brown-fox-jumps-over-the-lazy-dog”

  • One of its most common uses is for separating words in a URL; take a look at the URL for this post.
  • However, dashes in variables can sometimes cause batch scripts and other programs, so be careful.

Here’s the helper function for convert into kebab case in javascript

	const toKebabCase = str =>
    str &&
      .map(x => x.toLowerCase())
	console.log(toKebabCase("Hello World"));
// hello-world

Lodash KebabCase

Converts string to kebab case


[string=''] (string): The string to convert.


(string): Returns the kebab cased string.

	_.kebabCase('Foo Bar');
// => 'foo-bar'

// => 'foo-bar'

// => 'foo-bar'

In JavaScript variable names cannot have a hyphen, it results in an error.

	let my-name = "Adam"
Uncaught ReferenceError: Invalid left-hand side in assignment

JavaScript parses hyphen as a Subtraction Operator (-).We can use hyphens in object property names.