aboutsummaryrefslogtreecommitdiff
path: root/files/es/web/javascript/reference/global_objects/number/parseint/index.html
blob: 5d2120ca5bac4ae7f4a08c0f8793a6f1c944fff1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
---
title: Number.parseInt()
slug: Web/JavaScript/Reference/Global_Objects/Number/parseInt
tags:
  - metodo
translation_of: Web/JavaScript/Reference/Global_Objects/Number/parseInt
original_slug: Web/JavaScript/Referencia/Objetos_globales/Number/parseInt
---
<div>{{JSRef}}</div>

<p>The <strong><code>Number.parseInt()</code></strong> method parses a string argument and returns an integer of the specified radix or base.</p>

<p>The <strong><code>Number.parseInt()</code></strong> El método Number.parseInt () analiza un argumento de cadena y devuelve un entero de la raíz o base especificada.</p>

<div>{{EmbedInteractiveExample("pages/js/number-parseint.html", "taller")}}</div>



<h2 id="Syntax">Syntax</h2>

<pre class="syntaxbox">Number.parseInt(<var>string,</var>[ <var>radix</var>])</pre>

<h3 id="Parameters">Parameters</h3>

<div>
<dl>
 <dt><code><var>string</var></code></dt>
 <dd>The value to parse. If this argument is not a string, then it is converted to one using the <code><a href="https://tc39.es/ecma262/#sec-tostring">ToString</a></code> abstract operation. Leading whitespace in this argument is ignored.</dd>
 <dt><code><var>radix</var></code><var> {{optional_inline}}</var></dt>
 <dd>An integer between <code>2</code> and <code>36</code> that represents the <em>radix</em> (the base in mathematical numeral systems) of the <code><var>string</var></code>. Be careful—this does <strong><em>not</em></strong> default to <code>10</code>!</dd>
</dl>
</div>

<h3 id="Return_value">Return value</h3>

<p>An integer parsed from the given <code><var>string</var></code>.</p>

<p>If the <code><var>radix</var></code> is smaller than <code>2</code> or bigger than <code>36</code>, and the first non-whitespace character cannot be converted to a number, {{jsxref("NaN")}} is returned.</p>

<h2 id="Description">Description</h2>

<p>This method has the same functionality as the global {{jsxref("parseInt", "parseInt()")}} function:</p>

<pre class="brush: js">Number.parseInt === parseInt // true</pre>

<p>and is part of ECMAScript 2015 (its purpose is modularization of globals). Please see {{jsxref("parseInt", "parseInt()")}} for more detail and examples.</p>

<h2 id="Polyfill">Polyfill</h2>

<pre class="brush: js">if (Number.parseInt === undefined) {
    Number.parseInt = window.parseInt
}
</pre>

<h2 id="Specifications">Specifications</h2>

<table class="standard-table">
 <thead>
  <tr>
   <th scope="col">Specification</th>
  </tr>
 </thead>
 <tbody>
  <tr>
   <td>{{SpecName('ESDraft', '#sec-number.parseint', 'Number.parseInt')}}</td>
  </tr>
 </tbody>
</table>

<h2 id="Browser_compatibility">Browser compatibility</h2>



<p>{{Compat("javascript.builtins.Number.parseInt")}}</p>

<h2 id="See_also">See also</h2>

<ul>
 <li>The {{jsxref("Number")}} object it belongs to.</li>
 <li>The global {{jsxref("parseInt", "parseInt()")}} method.</li>
</ul>