Difference between "keyword" and "function" - Javascript

Hey guys. I’m studying the book “Javascript - Absolute beginner’s guide”, and I’m a bit confused about the difference between “function” and “keyword”. Are they the same?
So for example “let” is defined by the book as a keyword, whereas “alert” is a function. I’m not sure if I understood the difference between them completely.
Thank you in advance!

2 Likes

Hi @Claudia_Fetter - welcome to the forums! Hope you are also enjoying the book :slight_smile:

One way to think about it is the following:

  • A function is a reusable piece of code that performs a specific task
  • A keyword is a reserved word (aka we shouldn’t use it for naming our own variables, functions, etc.) with a predefined meaning in the language

We can create our own functions, but keywords are defined by the JavaScript language. We can’t create new keywords.

Hope this helps.

Cheers,
Kirupa :upside_down_face:

Hi Kirupa,

definetely helped a lot! I borrowed the book in a local library where I live, but I’m planning to buy it once I have more resources, it is a very good book! Thank you for all the shared knowledge!

2 Likes

Yep, That’s right nice explanation.

1 Like